shouldAutorotateToInterfaceOrientation 不触发或者不执行的问题

注:

 

要翻转的时候,首先响应的方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
return YES则支持翻转,NO则不支持。

紧接着

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

被调用。这个方法是发生在翻转开始之前。一般用来禁用某些控件或者停止某些正在进行的活动,比如停止视频播放。
再来是

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

这个方法发生在翻转的过程中,一般用来定制翻转后各个控件的位置、大小等。可以用另外两个方法来代替:willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:   和  willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:

最后调用的是

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

这个方法发生在整个翻转完成之后。一般用来重新启用某些控件或者继续翻转之前被暂停的活动,比如继续视频播放。



 

UIViewController没有随着设备一起旋转的原因   转载

引用地址:http://blog.sina.com.cn/s/blog_6de189920101266h.html
对于iPhone app,UIViewController类提供了基本的视图管理模式。当设备改变方向的时候view controller的视图会自动随之旋转的。如果视图和子视图的autoresizing属性设置是对的,这时候视图又没有随着设备一起旋转,可能是以下的原因:

1.view controller没有完成代理方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

也要实现了shouldAutorotateToInterfaceOrientation方法,同时shouldAutorotateToInterfaceOrientation方法要返回YES来支持所有的旋转方向


2.view controller的UIView属性嵌入在UIWindow中,并非是一个附加的view controller

你可能会发现shouldAutorotateToInterfaceOrientation方法只会在view controller启动的时候被调用,不会因为设置的旋转而在被调用。这是因为view controller束缚着他们所管理的视图,view controller是用来处理时间的响应链的一部分。view controller是从UIResponder继承而来,同时他被插入到他所管理的视图和他的superview之间。因此,通常的做法是在你的app中有一个主view controller来作为响应链的一部分。通常来说会添加一个主view controller,例如UINavigationController, UITabBarController或者UIViewControllerUIWindow

例如

[myWindow addSubview:primaryViewController.view]; 

如果你添加了另外一个view controller的UIView属性到UIWindow(anotherController和主view controller在同一个等级上)

[myWindow addSubview:anotherController.view];

anotherController将不会接受旋转事件,只有第一个view controller(primaryViewController)会接受旋转事件。


3.你添加了view controller的UIView属性到UIWindow作为subview,但是过早的release它。

UIWindow会retain视图,而不是view controller。你不能过早的release他。UIApplicationDelegate子类中定义他为retain属性。


4.在UITabBarController或者UINavigationController中的子view controller没有对同一方向的支持。

为了确保所有的子view controller旋转正确,你的每一个view controller,每一个tab或者额navigation都要完成shouldAutorotateToInterfaceOrientation,而且必须支持对于同一方向的旋转,也就是说对于同一方向的位置要返回为YES。


5.重写-(id)init:或者 -(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle 方法的时候没有调用super。

对于对象的初始化,在你的view controller的init或者initWithNibName方法中必须要调用super。

/

音频视频播放:http://blog.sina.com.cn/s/blog_6f1a34260100tlvx.html

////////转载

 iphone提供了优秀的重力加速计,能够很灵敏地感应到手机的屏幕状态。在我们开发iphone应用时,为了提高用户体验,会来监听屏幕的当前状态。
对于UIViewController来说,提供了好几种方法。

    最简单的就是我们可以使用Interface Builder这个工具来帮助我们实现简单的屏幕界面适配,只需要在IB 中的Size Insepector 中通过对Autosizing 的
设置来实现。但这只能做到简单界面的实现,如果界面比较复杂,可能就需要我们通过代码来实现。

    第二个我们可以通过对 willAnimateRotationToInterfaceOrientation:duration:这个方法的重写来配置我们的自动旋转。

    第三,你也可以通过对willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:与willAnimateSencondHalfOfRotationToInterfaceOrientation:duration:两个方法的重写来更加精细地配置我们的自动旋转视图。特别需要注意 的就是前一个方法在执行时,此时的UIInterfaceOrientation仍然是旋转前的原有值,只有后一个方法在执行时UIInterfaceOrientation才是屏幕旋转后的值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值