如何在没有 IB 的情况下控制对象的自动调整大小?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[self positionViews];
}
-(void)positionViews {
UIInterfaceOrientation destOrientation = self.interfaceOrientation;
if (destOrientation == UIInterfaceOrientationPortrait ||
destOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[bLabel setFrame:CGRectMake(255, 10, 270, 60)];
} else {
[bLabel setFrame:CGRectMake(377, 10, 270, 60)];
}
}
bLabel
是自定义对象。
当 iPad(设备)旋转时,bLable
也会旋转。 但出现时间滞后。 因此旋转运动不平滑。
我的代码有什么错误? 如何自然地控制没有 IB 的对象的自动调整大小?
请告诉我你的建议。谢谢!!!
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[self positionViews];
}
-(void)positionViews {
UIInterfaceOrientation destOrientation = self.interfaceOrientation;
if (destOrientation == UIInterfaceOrientationPortrait ||
destOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[bLabel setFrame:CGRectMake(255, 10, 270, 60)];
} else {
[bLabel setFrame:CGRectMake(377, 10, 270, 60)];
}
}
bLabel
is Cutomed Object.
When IPad(device) rotates, bLable
is rotated.
But appear time lag.
So rotation motion is not smooth.
What is my code's faults?
How control autosizing of object without IB naturally?
Please tell me your advice. Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在视图上查找的属性是 autoresizingMask。就像在 IB 中一样设置它。以下是可用的值:
例如,如果您想要具有固定边距的灵活宽度和高度,您可以这样做:
The property you are looking for on the view is autoresizingMask.Set this just as you would in IB. Here are the values available:
For example, if you want a flexible width and height with fixed margins you would do:
您可以:
设置 UIView 的 autoresizingMask(如果可以)
自动为您调整大小。
如果两个设备方向之间的布局差异太大,您还可以在旋转动画期间调用的 UIViewController 方法
willAnimateRotationToInterfaceOrientation:duration:
中更改视图,而不是使用didRotateFromInterfaceOrientation:
在动画事务之后调用。您从
willAnimateRotationToInterfaceOrientation:duration:
对视图的可动画属性(frame、bounds、center、transform、alpha、backgroundColor、contentStretch)调用的任何更改也将在旋转。You can either :
set your UIView's autoresizingMask, if it can be
automatically resized for you.
If the layout between 2 device orientation is too different, you can also change your views in the UIViewController's method
willAnimateRotationToInterfaceOrientation:duration:
which is called during rotation animation, instead of usingdidRotateFromInterfaceOrientation:
which is called AFTER the animation transaction.Any changes you call on your views' animatable properties (frame, bounds, center, transform, alpha, backgroundColor, contentStretch) from
willAnimateRotationToInterfaceOrientation:duration:
will also be animated during the rotation.