zoukankan      html  css  js  c++  java
  • 自定义Notification来实现rotate

    如果AViewContorller通过addSubview增加BViewController的view到界面中,当旋转iphone时,AViewController可以接到shouldAutorotateToInterfaceOrientation和- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration消息,但是在BViewController中是没有办法接到这个二
    个消息的(目前我发现是这样的),但是如果是通过navigationController然后通过- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated这个方式
    加入BViewController的话,是可以响应到二个方法的.
    但是在我的工程中我需要通过AddSubview来增加BViewController的View,但是也希望旋转时也能接受到device旋转的消息.

    目前我找到一种方法,共享给大家:

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotificati*****];     
     [[NSNotificationCenter defaultCenter] addObserver:self  
                                                 selector:@selector(didRotate:)  
                                                     name:@"UIDeviceOrientationDidChangeNotification"   
                                                   object:nil];
    - (void) didRotate:(NSNotification *)notification  
     {     
         UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];  
         if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)  
         {  
     
         }

     }

  • 相关阅读:
    WebService如何抛出干净的异常
    添加引用方式抛出和捕获干净的WebService异常
    Linq 分组(group by)求和(sum)并且按照分隔符(join)分割列数据
    API & HTTP 请求调试:Postman
    .NET Transactional File Manager
    IIS发布站点错误收集
    zk删除node模式
    zk watch机制及创建node机制
    zk client获取数据
    Zookeeper CLI
  • 原文地址:https://www.cnblogs.com/easonoutlook/p/2642808.html
Copyright © 2011-2022 走看看