Iphone 如何在模式更改时自动将文本字段和按钮设置在视图中心?
当我改变景观或肖像模式时,我想将文本字段、uibutton、标签和图像视图自动设置在UIView的中心。我的意思是当我改变方向时,文本字段、按钮和图像自动设置在视图的中心。如何使用interface builder或动态设置它们 通过编程,您可以设置视图的Iphone 如何在模式更改时自动将文本字段和按钮设置在视图中心?,iphone,uiimageview,uibutton,uitextfield,uiinterfaceorientation,Iphone,Uiimageview,Uibutton,Uitextfield,Uiinterfaceorientation,当我改变景观或肖像模式时,我想将文本字段、uibutton、标签和图像视图自动设置在UIView的中心。我的意思是当我改变方向时,文本字段、按钮和图像自动设置在视图的中心。如何使用interface builder或动态设置它们 通过编程,您可以设置视图的center属性。当检测到界面方向改变时,请执行此操作。为此,您必须剪切两个不同的帧。一个用于普通视图,另一个用于景观视图。然后在interFaceOrientationChange方法中,您必须设置新的帧。使用button.center=vi
center
属性。当检测到界面方向改变时,请执行此操作。为此,您必须剪切两个不同的帧。一个用于普通视图,另一个用于景观视图。然后在interFaceOrientationChange方法中,您必须设置新的帧。使用button.center=view.center属性 在UIView上使用自动调整大小属性,并相应地设置它。。。最方便的方法是用这种方法编写代码
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight )
{
//write your code specific to orientation
}
else if(fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//write your code specific to orientation
}
}