iOS实现多视图跳转(横屏,竖屏)

#import <UIKit/UIKit.h>

#define degreesToRadians(X) (M_PI * (X) / 180.0)


@interface HXViewController : UIViewController

{

    UITextField *txtField;

    UITextField * lTxtField;

    UIView *landScape;

    UIView *portrait;

    UIButton * pBu;

    UIButton *lBu;

}

//定义输出口IBOutlet,否则程序找不到输出口

@property (nonatomic,retain)IBOutlet UITextField *txtField;

@property (nonatomic,retain)IBOutlet UITextField *lTxtField;

@property (retain,nonatomic) IBOutlet UIView *landScape;

@property (retain,nonatomic)IBOutlet UIView * portrait;

@property (retain,nonatomic)IBOutlet UIButton *pBu;

@property (retain,nonatomic)IBOutlet UIButton *lBu;


- (IBAction)onClickButton:(id)sender;



@end







#import "HXViewController.h"


@interface HXViewController ()


@end


@implementation HXViewController


@synthesize txtField = _txtField;;

@synthesize  landScape = _landScape;

@synthesize portrait = _portrait;

@synthesize lTxtField = _lTxtField;

@synthesize pBu = _pBu;

@synthesize lBu = _lBu;


- (void)dealloc

{   //重写dealloc函数

    //每当定义了一个成员变量,就要在dealloc函数中release

    [_txtField release];

    [_landScape release];

    [_portrait release];

    [_lTxtField release];

    [_pBu release];

    [_lBu release];

    [super dealloc];

}


- (IBAction)onClickButton:(id)sender

{

    

//    NSLog(@"nihao");

//    self.txtField.text = @"p ni hao!";

//    self.lTxtField.text = @"l hello World!";//????????????

    if (self.view == self.portrait)

    {

       // NSLog(@"nihao");

//        txtField.text = @"p ni hao!";

        self.txtField.text = @"p ni hao!";

    }else if(self.view == self.landScape)

    {

        //lTxtField.text = @"l hello World!";//传递不出去,原因???????????用self

        self.lTxtField.text = @"l hello World!";

        

    }    

}



- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait )

    {

        self.view = self.portrait;

        self.view.transform = CGAffineTransformIdentity;

        self.view.transform

            CGAffineTransformMakeRotation(degreesToRadians(0));

        self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);

        self.txtField.text = @"p ni hao!";

    }else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {

        self.view = self.landScape;

        self.view.transform = CGAffineTransformIdentity;

        self.view.transform =

        CGAffineTransformMakeRotation(degreesToRadians(-90));

        self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);

    }else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

            self.view = self.portrait;

            self.view.transform = CGAffineTransformIdentity;

            self.view.transform =CGAffineTransformMakeRotation(degreesToRadians(180));self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);

        }else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {

            self.view = self.landScape;

            self.view.transform = CGAffineTransformIdentity;

            self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));

            self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);}

    

}


- (void)viewDidUnload

{

    self.portrait = nil;

    self.landScape = nil;

    self.pBu = nil;

    self.lBu = nil;

    [super viewDidUnload];

}


//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

//{

//    return YES;

//}


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    //获得应用程序的Documents文件夹

    NSArray * myPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *myDocPath = [myPath objectAtIndex:0];

    NSLog(@"%@",myDocPath);

//  2013-12-06 09:22:21.525 test_1[698:907] /Users/anit/Library/Application Support/iPhone Simulator/6.1/Applications/7C21715A-A16E-4715-A5CE-EF0CE4362E4A/Documents


    

    //获得文件的完整路径

    NSString *fileMame = [myDocPath stringByAppendingPathComponent:@"test_1-Info.plist"];

    NSLog(@"%@",fileMame);

//    2013-12-06 09:22:21.527 test_1[698:907] /Users/anit/Library/Application Support/iPhone Simulator/6.1/Applications/7C21715A-A16E-4715-A5CE-EF0CE4362E4A/Documents/test_1-Info.plist

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}




@end





发布了32 篇原创文章 · 获赞 6 · 访问量 6万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章