我使用两个块在子视图上动态绘制一些按钮。一种计算纵向模式的帧,另一种计算横向模式的帧。它运作良好,但是当我旋转时,它会覆盖旧的。因此,我的某些按钮出现了两次。这是我检测方向的代码:
//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对象上
最佳答案
嗨,
尝试下面的代码,并在视图上分配所有按钮
将被删除。
for(UIButton *view in yourview.subviews)
{
[view removeFromSuperview];
}