-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
dispatch_async(dispatch_get_main_queue(), ^{
[SecView setFrame:CGRectMake(0, 0, 480, 320)];
[self.view addSubview:SecView];
});
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
[SecView removeFromSuperview];
});
}
{
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
dispatch_async(dispatch_get_main_queue(), ^{
[SecView setFrame:CGRectMake(0, 0, 480, 320)];
[self.view addSubview:SecView];
});
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
[SecView removeFromSuperview];
});
}
}
SecView是单独添加的视图,Orientation选Landscape。
本文介绍了一个iOS应用中针对横屏(Landscape)显示模式的视图切换方法。通过在设备旋转到横屏时动态添加和移除特定视图(SecView),实现了良好的用户体验。代码使用了Objective-C编写,并利用了dispatch_async确保UI更新在主线程中执行。
6358

被折叠的 条评论
为什么被折叠?



