【问题标题】:Turn off default rotate animation in iOS在 iOS 中关闭默认旋转动画
【发布时间】:2013-09-26 12:11:00
【问题描述】:

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

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

【问题讨论】:

  • 在正常状态下工作正常吗?
  • @Ganapathy 我描述的是正常状态 :)
  • 可以分享你的屏幕吗(隐藏官方内容)
  • @Ganapathy 别打扰,问题解决了)

标签: iphone ios cocoa-touch animation uikit


【解决方案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;
}

【讨论】:

  • 虽然您的代码示例非常主观,但我已经设法先提交动画,然后使用[UIView setAnimationsEnabled:NO];,然后在duration 时间间隔后将其设置为yes。像魅力一样工作。
【解决方案2】:

我发现最好的解决方案是在旋转前关闭动画,然后在旋转后将其关闭。

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

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    ...
    [UIView setAnimationsEnabled:YES];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    相关资源
    最近更新 更多