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)  
         {  
     
         }

     }

  • 相关阅读:
    c# 暴力破解中文编码方式
    vs调试 不能进入断点
    shell-的bash内部命令变量介绍与shift等
    shell-的特殊变量-难点理论
    shell-的特殊变量-进程状态变量$$ $! $? $_详解
    shell-的特殊变量-位置变量$0 $n $* $# $@详解
    shell-的变量-局部变量
    shell-的变量-全局变量
    shell-脚本开发基本规范及习惯
    shell-脚本的执行
  • 原文地址:https://www.cnblogs.com/easonoutlook/p/2642808.html
Copyright © 2011-2022 走看看