ios循环调用同一个接口_未调用iOS8接口循环方法

Since willAnimateRotationToInterfaceOrientation:duration: is deprecated in iOS8, one needs to use viewWillTransitionToSize:withTransitionCoordinator: instead.

However, this method does not get called in my view controller on iOS8.

Is there anything else, I need to implement, in order for this callback to work?

I cannot find anything in the documentation. The only thing I could find, was that it belongs to the new UIContentContainer protocol. However, even if I am adding this to the protocols of my controller explicitly, it does not work.

Any ideas?

解决方案

The viewWillTransitionToSize:withTransitionCoordinator: seems to only work if the interface is actually going to change size, meaning we have rotated 90 degrees. If you have a mask on your layout that only allows landscape, when rotation 180 degrees, the interface size doesn't change, so this method doesn't seem to be called.

I have worked around this in my app by instead registering to the UIDeviceOrientationDidChangeNotification notification like:

(In my view controller's viewWillAppear):

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

(An in my viewWillDisappear [remember to unsubscribe])

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];

My deviceOrientationDidChange: looks like:

- (void)deviceOrientationDidChange:(NSNotification *)notification {

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

[self willRotateToInterfaceOrientation:orientation duration:1.0];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值