0
我有一個簡單的視圖控制器與一些自定義按鈕添加到它。視圖控制器不旋轉
-(void)viewWillLayoutSubviews {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
NSLog(@"Detected IPAD");
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
NSLog(@"Orientation is PORTAIT");
UIImage *serviceTask = [UIImage imageNamed:@"main_l_serviceorder.png"];
btnServiceOrder = [UIButton buttonWithType:UIButtonTypeCustom];
btnServiceOrder.frame = CGRectMake(143.0, 37.0, 226.0, 200.0);
[btnServiceOrder setBackgroundImage:serviceTask forState:UIControlStateNormal];
[btnServiceOrder addTarget:self action:@selector(gotoServiceOrders:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnServiceOrder];
//similar codes goes here..
}
else
{
NSLog(@"Orientation is LANDSCAPE");
//similar codes goes here..
}
}
}
我也有添加爲iOS6的shouldAutorotateToInterfaceOrientation折舊以下,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
NSLog(@"Rotated!.");
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskLandscape | UIInterfaceOrientationMaskPortrait);
}
視圖控制器加載在波泰特模式而已!.. 請指引我!