XcodeでデリゲートviewWillTransitionToSize:withTransitionCoordinator:を使用するか、Xamarin.iOSでViewWillTransitionToSizeを使用して、画面を回転するときにビューのサイズを変更できます。
XcodeでのObjective-Cでのサンプル・コード:
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
// Code here will execute before the rotation begins.
// Equivalent to placing it in the deprecated method -[willRotateToInterfaceOrientation:duration:].
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
// Place code here to perform animations during the rotation.
// You can pass nil for this closure if not necessary.
// Reorganize views, or move child view controllers.
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
//Update UI
}
if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
//Update UI
}
}completion:^(id<UIViewControllerTransitionCoordinatorContext> context){
// Code here will execute after the rotation has finished.
// Equivalent to placing it in the deprecated method -[didRotateFromInterfaceOrientation:].
// Do any cleanup, if necessary.
}];
}
Xamarin.iOSのC#でのサンプルコード:
public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
{
base.ViewWillTransitionToSize(toSize, coordinator);
coordinator.AnimateAlongsideTransition((IUIViewControllerTransitionCoordinatorContext) => {
if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown)
{
//Update UI
}
if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft|| UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight)
{
//Update UI
}
}, (IUIViewControllerTransitionCoordinatorContext) => {
//Transition Completion
});
}
@DaleYYは、私の答えはあなたを助けるをしましたか? –