相关疑难解决方法(0)

iOS 8轮换方法弃用 - 向后兼容性

在iOS 8中,不推荐使用接口轮换方法.这包括:

  • willRotateToInterfaceOrientation:duration:
  • didRotateFromInterfaceOrientation:
  • willAnimateRotationToInterfaceOrientation:duration:

替代方法包括:

  • willTransitionToTraitCollection:withTransitionCoordinator:
  • viewWillTransitionToSize:withTransitionCoordinator:

如果未实现新的旋转方法,并且使用iOS 8 SDK编译项目,则视图控制器将不会接收调用 - 不推荐的旋转方法.

我担心的是:使用iOS 7 SDK构建的AppStore中的应用程序会发生什么变化?是否仍会在iOS 8设备上调用已弃用的旋转方法?

编辑:

仍然会调用旋转方法,但iOS 8中存在一些更改/问题/错误.

现在也是UIScreen面向接口的

rotation ios ios8

52
推荐指数
3
解决办法
5万
查看次数

即使未在 - (NSUInteger)supportedInterfaceOrientations中定义,也检测UIViewController上的接口旋转

我有一个UIViewController在主视图上处理几个UIImageViews.在底部是一个UIToolbar,其中有几个项目可以与之交互.

现在,当我旋转设备时,我不希望viewController旋转,而只是UIImageViews.换句话说,底部的工具栏将位于左侧(或右侧),但imageViews将正确旋转.

所以,通过使用方法

- (BOOL)shouldAutoRotate {
   return YES;
}
Run Code Online (Sandbox Code Playgroud)

结合

- (NSUInteger)supportedInterfaceOrientations {
   return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// rotate the image views here
}
Run Code Online (Sandbox Code Playgroud)

设备上的任何旋转都不会被执行,因为只支持一个接口方向(UIInterfaceOrientationMaskPortrait).但是当我在supportedInterfaceOrientations-method中添加另一个支持的接口方向时,视图控制器也会旋转.

即使只支持一个方向,如何检测视图控制器的旋转?或者是否有另一种可能性根据不断变化的设备方向旋转UIViews?

谢谢你的帮助!

ios6

6
推荐指数
1
解决办法
4077
查看次数

如何知道AppDelegate中的方向已更改

设备如何知道方向变化的功能是 - (void)viewWillLayoutSubviews和 - (void)viewDidLayoutSubviews但是,它们只是在控制器中; 现在我想知道是否有这样的函数来了解文件AppDelegate.m中方向的变化

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated {

    UINavigationBar *morenavbar = navigationController.navigationBar;
    UINavigationItem *morenavitem = morenavbar.topItem;
    //We don't need Edit button in More screen.
    morenavitem.rightBarButtonItem = nil;
    morenavitem.title = nil;
    UIImage *backgroundImage = [UIImage imageNamed:@"nav.png"];

    [morenavbar setBackgroundImage:backgroundImage 
         forBarMetrics:UIBarMetricsDefault];

    UIDeviceOrientation currentDeviceOrientation = 
           [[UIDevice currentDevice] orientation];
    UIInterfaceOrientation currentInterfaceOrientation = 
           [[UIApplication sharedApplication] statusBarOrientation];
    if (UIDeviceOrientationIsLandscape(currentDeviceOrientation)||
        UIDeviceOrientationIsLandscape(currentInterfaceOrientation)){
        UIImage *backgroundImageLandscape = [UIImage imageNamed:@"navbar_landscape.png"];
        [morenavbar setBackgroundImage:backgroundImageLandscape forBarMetrics:UIBarMetricsDefault];
    }

}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c screen-orientation ios

3
推荐指数
1
解决办法
3608
查看次数

标签 统计

ios ×2

ios6 ×1

ios8 ×1

iphone ×1

objective-c ×1

rotation ×1

screen-orientation ×1