【发布时间】:2012-04-14 04:40:05
【问题描述】:
我使用两个块在我的子视图上动态绘制一些按钮。一个计算纵向模式的帧数,另一个计算横向模式的帧数。它运作良好,但当我旋转时,它会覆盖旧的。因此,我的一些按钮来了两次。这是我检测方向的代码:
//i have defined blocks in viewDidLoad: and everything is ok till here
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
dispatch_async(dispatch_get_main_queue(), PortraitBlock);
}
else
{
dispatch_async(dispatch_get_main_queue(), LandscapeBlock);
}
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
现在,如何清理添加按钮的视图?
注意:我在 UIView 对象上添加按钮,并且该对象也在 UIScrollView 对象上
【问题讨论】:
-
@illis 如果按钮被添加两次然后给按钮标签并检查按钮是否存在然后不要添加它
-
您无需在每次旋转设备时重新绘制按钮。只需将它们移动到适当的位置并根据需要更改外观即可。
-
我需要有关您的特殊情况的更多信息才能提供帮助。
-
@SVGreg 谢谢,我解决了