UIViewController旋转方法

什么对象是dipatching的UIViewController旋转的方法调用,即负责:

- shouldAutorotateToInterfaceOrientation: 

- willRotateToInterfaceOrientation:时间: 

- willAnimateFirstHalfOfRotationToInterfaceOrientation:时间: 

- willAnimateSecondHalfOfRotationFromInterfaceOrientation:时间: 

- didRotateFromInterfaceOrientation:

我猜想,UIApplication(但也许是AppDelegate或UIWindow)。

 

看来,UIApplication是派遣一个信息,活动视图控制器。

但如何做你的视图控制器实例得到这些信息?

该邮件被转发到的第一个视图控制器的观点已被添加到UIWindow实例。

这可以归结为3个基本情况:

 

    1. 他们的观点是的ViewController 
      直接添加到UIWindow 
      (例如单一视图的应用程序)

 

    1. 在导航控制器 
      导航的应用程序,则 
      导航控制器转发 
      信息的积极的意见看法 
      控制器。

 

    1. 在一个标签栏标签栏控制器 
      基于应用程序,那么标签栏 
      控制器转发邮件 
      活动的意见看法控制器(或 
      积极导航控制器)。

 

您将有问题,如果你是建立一个与多个视图的应用程序,但不使用导航控制器或一个标签栏控制器。 如果您在交换意见,并出UIWindow实例手动,您将不会收到这些消息可靠。

 

 

 

首先重写UIViewController方法:

Java代码  

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {  

      

    return YES;  

}  

 你也可以根据toInterfaceOrientation的不同值来判断是否允许旋转。这个传入参数有四种取值:

Java代码  

UIInterfaceOrientationLandscapeLeft 横向Home键在左  

UIInterfaceOrientationLandscapeRight 横向Home键在右  

UIInterfaceOrientationPortrait 正常  

UIInterfaceOrientationPortraitUpsideDown 反向Home键在上  

 

可以在下面的方法中处理旋转后要重画的组件,或者重载另一个NIB文件。 

Java代码  

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {  

// 重新加载一个Nib文件  

if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {  

        [[NSBundle mainBundle] loadNibNamed:@"LoginViewLandscape" owner:self options:nil];  

    }else {  

        [[NSBundle mainBundle] loadNibNamed:@"LoginView" owner:self options:nil];  

    }  

// 重写Toolbar  

// Set Toolbar  

    UIBarButtonItem *newChat = [[UIBarButtonItem alloc] initWithTitle:@"新增" style:UIBarButtonItemStylePlain target:self action:@selector(createChat:)];  

    UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithTitle:@"刷新" style:UIBarButtonItemStylePlain target:self action:@selector(refresh:)];  

    UIBarButtonItem *deleteChat = [[UIBarButtonItem alloc] initWithTitle:@"删除" style:UIBarButtonItemStylePlain target:self action:@selector(deleteChat:)];  

      

    self.deleteItem = deleteChat;  

    self.deleteItem.enabled = NO;  

    UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:NULL];  

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {  

        fixedItem.width = 155;  

    }else {  

        fixedItem.width = 75;  

    }  

      

    NSArray *toolBarItems = [[NSArray alloc] initWithObjects:newChat, fixedItem, refresh, fixedItem, self.deleteItem, nil];  

      

    [self setToolbarItems:toolBarItems];  

    [toolBarItems release];  

    [newChat release];  

    [deleteChat release];  

    [fixedItem release];  

    [refresh release];  

}  

转载于:https://www.cnblogs.com/pengyingh/articles/2382077.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值