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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章