【问题标题】:IOS rotate device without rotation animationIOS旋转设备没有旋转动画
【发布时间】:2011-09-17 20:24:11
【问题描述】:

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

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

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

谢谢!

安德鲁斯

【问题讨论】:

    标签: iphone ios xcode uiview rotation


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

    【讨论】:

    • presentModalViewController 已弃用。
    猜你喜欢
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-07
    • 1970-01-01
    • 2022-11-01
    相关资源
    最近更新 更多