FirstApp,iphone开发学习总结9,旋转

添加Rotation文件,用类别为UITabBarController添加旋转:

// Rotation.h文件
#import <Foundation/Foundation.h>

@interface UITabBarController(Rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)x;
@end

 Rotation.m文件:

#import  " Rotation.h "

@implementation UITabBarController(Rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)x {
     return YES;
}

@end

在ButtonViewController.m文件中添加:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)x
{
     return YES; //此处判定方向,达到要求才旋转
}

//此时可以旋转了

修改right按钮,修改ButtonViewController.h:

@interface ButtonViewController : UIViewController{
    UIButton *rightBtn;
}
@end

 修改ButtonViewController.m文件内的- (void)viewDidLoad:

- ( void)viewDidLoad
{
     // ..
    rightBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // 修改
    // ..
    [rightBtn setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; //添加,此处可用 |
    
     // ..
}

 

不是很具体,这是总结。

求指点~

你可能感兴趣的:(iPhone开发)