旋转风景模式
问题描述:
我做的是在portroide模式下显示10张图像作为网格和3张图像,我做的是当我将模拟器旋转到风景时,我必须显示4个图像。它也使用代码显示旋转风景模式
if(self.interfaceorientation == UIIntefaceorientationPortrait) {
[self abc];
else {
[self abclandscape];
}
这里ABC和abclandscape两个函数它工作正常,但是,它从最初的手段运作的形式开始,如果我旋转为横向模式或纵向模式下正常工作。而在中间,如果我从横向到纵向旋转它不会去[自我abc]功能。我该如何解决这个问题?
答
你可以做的是使用UIViewController委托或使用NSNoticationCenter。
I.E.添加在你的 “viewDidLoad中”:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil];
并添加功能:
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation))
{
// Do one thing
}
else
{
// Do something else
}
}
答
@mahesh在shouldAutoRototate方法
use
if(self.interfaceorientation == UIIntefaceorientationPortrait||self.interfaceorientation == UIIntefaceorientationPortraitUp..)
{} 其他 { }