我已经以编程方式创建了一个View,一个UIImageView和一个Button。问题是,如果设备从纵向切换为横向,我需要更新其位置,该怎么办?
这应该是检查设备处于纵向还是横向模式的代码
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
}
else
{
}
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
//change the frame for sideways direction
btn.frame=CGRectMake(x,y,width,height);
imgView.frame=CGRectMake(x,y,width,height);
view.frame=CGRectMake(x,y,width,height);
}
else
{
//change the frame for up/down
btn.frame=CGRectMake(x,y,width,height);
imgView.frame=CGRectMake(x,y,width,height);
view.frame=CGRectMake(x,y,width,height);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句