我有一个简单的视图控制器,其中添加了一些自定义按钮。
-(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 is depreciated.,
- (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);
}
Viewcontroller 仅在 PORTAIT 模式下加载!.. 请指导我!