【发布时间】:2011-01-21 18:13:44
【问题描述】:
我正在尝试在 Xcode 中创建一个应用程序,当手机从一个方向旋转到另一个方向时,它将切换到新视图。
这里是“switchviewcontroller.h”文件代码:
#import <UIKit/UIKit.h>
@interface SwitchViewController : UIViewController {
}
-(IBAction)switchview:(id)sender;
@end
这里是“switchviewcontroller.m”文件代码:
#import "SwitchViewController.h"
#import "secondview.h"
@implementation SwitchViewController
-(IBAction)switchview:(id)sender
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
{
[[secondview alloc] initWithNibName:@"secondview" bundle:[NSBundle mainBundle]];
}
}
我得到了问题中显示的 2 个错误,所以它不起作用。
【问题讨论】:
-
代码显示不正确:(
-
注意:您可以在
didRotateFromInterfaceOrientation的if 子句中使用UIDeviceOrientationIsLandscape(fromInterfaceOrientation)以使代码更简单。
标签: objective-c cocoa-touch ios ios4