久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從滾動視圖中刪除子視圖?

how to remove subviews from scrollview?(如何從滾動視圖中刪除子視圖?)
本文介紹了如何從滾動視圖中刪除子視圖?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何從我的滾動視圖中刪除所有子視圖...

how do i remove all subviews from my scrollview...

我在滾動視圖中有一個 uiview 和它上方的按鈕,如下所示....

i have a uiview and a button above it in the scrollview something like this....

這是我在滾動視圖中添加子視圖的代碼

here is my code to add subview in scroll view

-(void)AddOneButton:(NSInteger)myButtonTag {
lastButtonNumber = lastButtonNumber + 1;

if ((lastButtonNumber == 1) || ((lastButtonNumber%2) == 1)) {
btnLeft = 8;}
else if ((lastButtonNumber == 2) || ((lastButtonNumber%2) == 0)) {
btnLeft = 162;
}
CGRect frame1 = CGRectMake(btnLeft, btnTop, 150, 150);
CGRect frame2 = CGRectMake(btnLeft, btnTop, 150, 150);
UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom];
Button.frame = frame1;
Button.tag = myButtonTag;
[Button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[Button setBackgroundColor:[UIColor clearColor]];
[Button setBackgroundImage:[UIImage imageNamed:@"WaitScreen.png"] forState:UIControlStateHighlighted];

    GraphThumbViewControllerobj = [[GraphThumbViewController alloc] initWithPageNumber:[[GraphIdArray objectAtIndex:myButtonTag]intValue]];
    GraphThumbViewControllerobj.view.frame=frame2;
    GraphThumbViewControllerobj.lblCounter.text=[NSString stringWithFormat:@"%d of %d",myButtonTag+1,flashCardsId.count];
    GraphThumbViewControllerobj.lblQuestion.text=[flashCardText objectAtIndex:myButtonTag];
    [myScrollView addSubview:GraphThumbViewControllerobj.view];


[myScrollView addSubview:Button];


if ((lastButtonNumber == 2) || ((lastButtonNumber%2) == 0)) {
btnTop = btnTop + 162;
}
if (btnTop+150 > myScrollView.frame.size.height) {
myScrollView.contentSize = CGSizeMake((myScrollView.frame.size.width), (btnTop+160));}
}

這是刪除子視圖的代碼

if(myScrollView!=nil)
{
        while ([myScrollView.subviews count] > 0) {
            //NSLog(@"subviews Count=%d",[[myScrollView subviews]count]);
            [[[myScrollView subviews] objectAtIndex:0] removeFromSuperview];
}

推薦答案

要從任何視圖中刪除所有子視圖,您可以遍歷子視圖并為每個子視圖發(fā)送 removeFromSuperview 調用:

To remove all the subviews from any view, you can iterate over the subviews and send each a removeFromSuperview call:

// With some valid UIView *view:
for(UIView *subview in [view subviews]) {
    [subview removeFromSuperview];
}

不過,這完全是無條件的,并且會刪除給定視圖中的所有子視圖.如果你想要更細粒度的東西,你可以采取幾種不同的方法:

This is entirely unconditional, though, and will get rid of all subviews in the given view. If you want something more fine-grained, you could take any of several different approaches:

  • 維護您自己的不同類型的視圖數組,以便稍后以相同的方式向它們發(fā)送 removeFromSuperview 消息
  • 保留您創(chuàng)建它們的所有視圖并保留指向這些視圖的指針,以便您可以根據需要單獨發(fā)送它們 removeFromSuperview
  • 在上述循環(huán)中添加 if 語句,檢查類是否相等.例如,要僅刪除視圖中存在的所有 UIButton(或 UIButton 的自定義子類),您可以使用以下內容:
  • Maintain your own arrays of views of different types so you can send them removeFromSuperview messages later in the same manner
  • Retain all your views where you create them and hold on to pointers to those views, so you can send them removeFromSuperview individually as necessary
  • Add an if statement to the above loop, checking for class equality. For example, to only remove all the UIButtons (or custom subclasses of UIButton) that exist in a view, you could use something like:
// Again, valid UIView *view:
for(UIView *subview in [view subviews]) {
    if([subview isKindOfClass:[UIButton class]]) {
        [subview removeFromSuperview];
    } else {
        // Do nothing - not a UIButton or subclass instance
    }
}

這篇關于如何從滾動視圖中刪除子視圖?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
Limiting the scrollable area in UIScrollView(限制 UIScrollView 中的可滾動區(qū)域)
Setting up UIScrollView to swipe between 3 view controllers(設置 UIScrollView 在 3 個視圖控制器之間滑動)
主站蜘蛛池模板: 亚洲日日夜夜 | 国产精品99久久久久久久久久久久 | 久久国产亚洲 | 日韩中文av在线 | a级大片免费观看 | 亚洲国产69 | 国产羞羞视频在线观看 | 日韩插插 | 欧美三级在线 | 99在线免费视频 | 91精品久久久久久综合五月天 | 亚洲第一天堂 | 欧美成视频| 欧美精品久久久久 | 亚洲国产视频一区 | 欧美精品久久久久 | 欧美日韩国产中文 | 国产成人高清 | 一级全黄少妇性色生活免费看 | 91.com在线观看 | 欧美成人手机视频 | 国产剧情一区二区三区 | 97国产成人 | 久久亚洲欧美日韩精品专区 | 免费亚洲婷婷 | 国产2区| 日韩久久久久 | 99精品福利视频 | 亚洲444eee在线观看 | 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 中文在线播放 | 亚洲精品一区中文字幕乱码 | 亚洲成人一二三 | 国产成人jvid在线播放 | 精品日韩一区二区 | 九九九久久国产免费 | 国内精品久久久久久 | 毛片一级片 | 日韩福利 | 国产欧美日韩在线观看 | 男人天堂国产 |