很多时候对于不同的版本,随设备的旋转以后,相应的Button的大小如果不做相应的改变,这很影响视图的美观和布局;下面是小编的个人看法
UIButton *button = [[UIBtton alloc]init];
button.frame =CGRectMake(320/2-100/2,60,100,80);
button.tag = 101;
[button setTitle:@"present" forState:UIControlStateNormal];
buttton.backgroundColor =[UIColor redColor];
[button addTarget:self action:@selector(presentModalVC) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
NSLog(@"duration:%f",duration);
UIView *button =[slef.view viewWithTag:101];
if(toInterfaceOrientation==UIInterfaceOrientationMaskPortrait){
button.frame =CGRectMake(320/2-100/2, 200, 100, 60);//power键向下的时候
}else{
button.frame =CGRectMake(480/2-100/2, 200, 100, 60);//这时设备旋转后,原来的长宽调换了
}
}
如果你有更好的方法或者疑问的话 请加QQ:1649419270 微信:meixianLYD