如何在绘图前清除子视图的内容

ilh*_*ctn 1 uibutton uiview ipad ios

我使用两个块动态地在子视图上绘制一些按钮.一个计算纵向模式的帧,另一个计算景观.它工作得很好但是当我旋转时,它会写入旧的.因此,我的一些按钮来了两次.这是我检测oriantation的代码:

//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);
    }
Run Code Online (Sandbox Code Playgroud)

现在,我如何清理视图我添加按钮?

注意:我在UIView对象上添加按钮,该对象也在UIScrollView对象上

Kar*_*tik 5

喜.,

尝试下面的代码,您将删除在视图上分配的所有按钮.

for(UIButton *view in yourview.subviews)
    {
        [view removeFromSuperview];
    }
Run Code Online (Sandbox Code Playgroud)