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

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

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

問題描述

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

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 調(diào)用:

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:

  • 維護您自己的不同類型的視圖數(shù)組,以便稍后以相同的方式向它們發(fā)送 removeFromSuperview 消息
  • 保留您創(chuàng)建它們的所有視圖并保留指向這些視圖的指針,以便您可以根據(jù)需要單獨發(fā)送它們 removeFromSuperview
  • 在上述循環(huán)中添加 if 語句,檢查類是否相等.例如,要僅刪除視圖中存在的所有 UIButton(或 UIButton 的自定義子類),您可以使用以下內(nèi)容:
  • 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
    }
}

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

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

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應(yīng)用程序式間隙)
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(設(shè)置 UIScrollView 在 3 個視圖控制器之間滑動)
主站蜘蛛池模板: 99久久久国产精品 | 夜夜骑夜夜| 亚洲精品蜜桃 | 精品福利一区 | 中国女人真人一级毛片 | 日本三级一区 | 欧美综合一区二区三区 | 久久夜色精品 | 精品一区二区三区三区 | 午夜免费看片 | 99视频免费 | 麻豆一区二区三区 | 成人久久网站 | 欧美成人综合 | 久久成人av | 日本免费黄色 | 99久久久国产精品 | 国产一区中文字幕 | 国产精品久久久国产盗摄 | 一区二区在线免费观看 | 在线不卡av | 免费看黄色大片 | 亚州av在线| 五月婷婷丁香综合 | 午夜看片 | 黄色国产精品 | 91在线视频观看 | 中文字幕免费看 | 视频一区二区在线 | 久热在线视频 | 国产精品1区2区 | 成人黄色小视频 | 欧美一区二区三区在线观看 | 国产一区二区视频在线播放 | 怡红院av | 午夜免费福利视频 | 精品国产aⅴ麻豆 | 伊人网视频| www.亚洲视频 | 久久精品国产视频 | 国产精品99久久久久久久久 |