1 #import "MyView.h" 2 3 @implementation MyView 4 5 -(instancetype)initWithFrame:(CGRect)frame 6 { 7 if (self = [super initWithFrame:frame]) { 8 _lable =[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; 9 _lable.backgroundColor = [UIColor redColor]; 10 [self addSubview:_lable ]; 11 } 12 return self; 13 } 14 15 -(void)layoutSubviews 16 { 17 if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) { 18 19 _lable.frame = CGRectMake(0, 0, 400, 30); 20 21 22 }else{ 23 24 _lable.frame = CGRectMake(0, 0, 100, 30); 25 } 26 NSLog(@"天天就知道旋转"); 27 } 28 @end