在肖像和风景之间切换 [英] switch between portrait and landscape

查看:66
本文介绍了在肖像和风景之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采取了两种观点,一种是纵向和横向,我想在旋转时切换视图,我正在使用下面的代码,但是它不起作用,请问我是哪里错了,因为我是iPhone开发的新手.没有在ViewDidLoad方法中实现任何功能,我也应该在那里实现任何功能吗?

i have taken two views one is portrait and landscape,i want the switch the view on rotation i am using below code but its not working,may i know where i am going wrong as i am new to iphone development.i have not implemented anything in ViewDidLoad method,should i implement anything there as well?

- (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中:-

In 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

希望我的回答对您有帮助...如果没有,请告诉我您的身份,我将向您发送该项目.

Hope My Answer Helps You... If Not Please Tell me ur id I will Send u the Project.

这篇关于在肖像和风景之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆