我拍摄了两个视图,一个是纵向和横向,我想要切换旋转视图,我正在使用下面的代码,但它不起作用,我可能知道我哪里出了问题,因为我是iPhone开发的新手。我还没有实现任何东西在 ViewDidLoad 方法中,我也应该在那里实现任何东西吗?
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
self.portrait.hidden = YES;
self.landscape.hidden = NO;
} else {
self.portrait.hidden = NO;
self.landscape.hidden =YES;
}
return YES;
}
I have showed To Images in Two Views One in Horizontal and one in Vertical....
在 ViewController.m 中:-
@interface OrientationTutorialViewController : UIViewController
{
IBOutlet UIView *portraitView;
IBOutlet UIView *landscapeView;
}
@property (nonatomic, retain) IBOutlet UIView *portraitView;
@property (nonatomic, retain) IBOutlet UIView *landscapeView;
@end
IN .h :-
@implementation OrientationTutorialViewController
@synthesize portraitView, landscapeView;
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
- (void) orientationChanged:(id)object
{
UIInterfaceOrientation interfaceOrientation = [[object object] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = self.portraitView;
}
else
{
self.view = self.landscapeView;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)dealloc
{
[super dealloc];
}
@end
希望我的回答对您有帮助...如果没有,请告诉我您的 ID,我会将项目发送给您。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)