[英]How to add subview to uiscrollview to start of content (before first subview)?
[英]How to clear the content of subview before drawing
我使用兩個塊在子視圖上動態繪制一些按鈕。 一種計算縱向模式的幀,另一種計算橫向模式的幀。 它運作良好,但是當我旋轉時,它會覆蓋舊的。 因此,我的某些按鈕出現了兩次。 這是我檢測方向的代碼:
//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];
}
從視圖中刪除視圖之前,請先檢查該類,然后再將其刪除。 之后,您可以根據方向在屏幕上添加按鈕。
for(UIView *view in [View to add buttons].subviews)
{
if ([view isKindOfClass:[UIButton class]]) [view removeFromSuperview];
}
如果您使用任何customButton
,請提及您的customButtonClassName
代替UIButton
。
完全不添加新按鈕。 只需更改舊框架。
如果需要添加新按鈕。 只需刪除舊的!! 要刪除所有子視圖,可以使用:
for(UIView* view in self.view.subviews)
{
[view removeFromSuperview];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.