转屏




症状:

willRotateToInterfaceOrientation在ios5地下不执行,ios6 地下没事儿。


原因:

与 add subview 有关

具体原因,之前改了一段代码,详细参看,弹出键盘的怪事儿。导致页面结构变了。


结论:

看来ios 5 和  6 ,关于willRotateToInterfaceOrientation 是否执行,还是有点差别的。


解决办法,比较hack,

http://stackoverflow.com/questions/8016479/ios-5-willrotatetointerfaceorientationduration-not-called-when-first-loading-c



Since I'm pressed for time I've had to work around this odd behaviour and manually call the orientation methods in viewDidLoad. This is a bit of a hack but it's working fine so far.

In viewDidLoad I added this:

if ( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.0") ) {
    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    [self willRotateToInterfaceOrientation:interfaceOrientation duration:0.2f];
}

I've then added this in a common header file:

// iOS Version Checking
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

I got the iOS version checking defines from an answer to this question on SO.

Since this is a bit of a hack I will leave this question unanswered for a little while just in case someone else finds a better way.



http://stackoverflow.com/questions/1516268/willrotatetointerfaceorientation-not-being-called


这个讲得也很好,虽然我已经知道了。

Is this views viewController a subview of some other root view controller thats not a navigation controller? if so then the call does not propagate to the subviews controller, so that might be why your view isnt rotating.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当 Android 设备的方向改变时,会触发 Activity 的生命周期事件。您可以通过在 Activity 中重写这些事件来实现响应屏幕方向更改的代码。例如,您可以使用 onConfigurationChanged() 方法来处理屏幕方向更改时的对话框。在此方法中,您可以检查当前方向并相应地更新对话框的位置和大小。 以下是处理对话框在屏幕方向更改时的示例代码: ``` @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (mDialog != null && mDialog.isShowing()) { WindowManager.LayoutParams params = mDialog.getWindow().getAttributes(); if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { params.width = (int) (getResources().getDisplayMetrics().widthPixels * 0.6); params.height = (int) (getResources().getDisplayMetrics().heightPixels * 0.5); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ params.width = (int) (getResources().getDisplayMetrics().widthPixels * 0.8); params.height = (int) (getResources().getDisplayMetrics().heightPixels * 0.3); } mDialog.getWindow().setAttributes(params); } } ``` 在此示例代码中,我们首先检查对话框是否正在显示。如果是,则获取对话框的当前参数。然后,我们检查屏幕的新方向,并根据需要更新对话框的宽度和高度。最后,我们将更新后的参数应用于对话框的窗口。 请注意,您需要在您的 Activity 中将 android:configChanges 属性设置为 "orientation",以确保 Activity 不会在方向更改时重新启动。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值