1

当我将 iDevice 形式的纵向旋转为横向时,屏幕旋转正常,但我看到黑色边框随之移动,因此看起来更“真实”。我发现在 iOS 7 中看到它很尴尬,而且许多应用程序都反对这种行为(比如 Instagram)。

我想要做的是隐藏那些在旋转设备时看起来完全没有必要的黑色边框。如何禁用此标准动画?

4

2 回答 2

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;
}
于 2013-09-26T12:15:39.433 回答
1

I found the best solution is turn animation off before rotation, and turn it back after rotation.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                duration:(NSTimeInterval)duration
{
    ...
    [UIView setAnimationsEnabled:NO];
}

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    ...
    [UIView setAnimationsEnabled:YES];
}
于 2014-05-16T06:04:52.307 回答