当我将iDevice表单纵向旋转到横向时,屏幕旋转正常,但我看到黑色边框随之移动,因此它看起来更“真实”。我发现在iOS 7中看到它很尴尬,许多应用程序都破坏了这种行为(如Instagram)。
我想要做的是隐藏那些在旋转设备时看起来完全不必要的黑色边框。如何禁用此标准动画?
答案 0 :(得分:1)
在父视图控制器viewdidload方法中添加:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
然后添加此方法
- (void) didRotate:(NSNotification *)notification {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (UIInterfaceOrientationIsLandscape(orientation) && !self.modalViewController) {
[self presentModalViewController:carouselView animated:YES];
[Globals sharedGlobals].startedAtLandscape = YES;
}
if (UIInterfaceOrientationIsPortrait(orientation) && self.modalViewController) {
[self dismissModalViewControllerAnimated:YES];
[Globals sharedGlobals].startedAtLandscape = NO;
}
}
然后阻止动画:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
return NO;
}
return YES;
}
答案 1 :(得分:1)
我发现最佳解决方案是在旋转前关闭动画,并在旋转后将其关闭。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
...
[UIView setAnimationsEnabled:NO];
}
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
...
[UIView setAnimationsEnabled:YES];
}