IOS旋转设备没有旋转动画

时间:2011-09-17 20:24:11

标签: iphone ios xcode uiview rotation

实现类似于iPhone标准iPod应用程序效果的正确方法是什么 - 当设备旋转到横向模式时,视图会变为覆盖流量,但过渡类型会淡化,不是旋转屏幕?

这是我加载模态视图的方式:

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        carouselView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentModalViewController:carouselView animated:YES];
    }
}

谢谢!

安德

1 个答案:

答案 0 :(得分:2)

我后来发现使用这个解决方案更稳定:

在父视图控制器中(在我的例子中是标签视图控制器)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;
}