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

UIScrollView 幻象子視圖

UIScrollView phantom subviews(UIScrollView 幻象子視圖)
本文介紹了UIScrollView 幻象子視圖的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在使用 nib 文件加載視圖:

I am loading a view from a nib file using:

NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"AnalysisView" owner:self options:nil];
AnalysisView *gridView = [nibViews objectAtIndex: 0];

nib 包含一個(gè)名為 gridScrollView 的滾動(dòng)視圖,在 AnalysisView 實(shí)現(xiàn)文件中,我有一個(gè)將視圖作為子視圖添加到滾動(dòng)視圖的方法:

The nib contains a scrollview called gridScrollView and in the AnalysisView implementation file I have a method which adds views as subviews to the scrollview:

for (NSInteger i = [results count] -1; i >= 0; i--) 
{
    Result *result = [results objectAtIndex:i];
    [self loadResult: result];
}

- (void) loadResult: (Result *) result
{
    NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"GridView" owner:self options:nil];
    GridView *gridView = [nibViews objectAtIndex: 0];
    gridView.tag = self.graphCount;

    CGRect gridFrame = gridView.frame;

    CGFloat yOffset = gridFrame.size.height * self.graphCount;
    gridView.frame = CGRectMake(0, yOffset, gridFrame.size.width, gridFrame.size.height);

    [self.gridScrollView addSubview: gridView];
    self.gridScrollView.contentSize = CGSizeMake(self.gridScrollView.frame.size.width, (yOffset + gridFrame.size.height));

    self.graphCount++;
}

我已將滾動(dòng)視圖委托設(shè)置為 AnalysisView 并連接了 do end decelaring 方法

I have set the scrollviews delegate to be AnalysisView and hooked up the did end decelaring method

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
      NSLog(@"%d", [scrollView.subviews count]);
}

當(dāng) scrollViewDidEndDecelerating 方法觸發(fā)時(shí),它報(bào)告子視圖的數(shù)量是 5.這些子視圖中的 3 個(gè)是我期望的 GridView.但是有 2 個(gè) UIImageViews 我不知道它們?yōu)槭裁丛谀抢?

When the scrollViewDidEndDecelerating method fires it reports that the number of subviews is 5. 3 of these subviews are GridViews which I expect. However there are 2 UIImageViews which I have no idea why they are there.

這是一個(gè)問(wèn)題,因?yàn)槲掖蛩阍?scrollViewDidEndDecelerating 方法中使用 viewWithTag 檢索視圖并在視圖上調(diào)用一個(gè)方法,但是每當(dāng)我嘗試檢索標(biāo)簽為 0 的視圖時(shí),我都會(huì)檢索其中一個(gè) UIImageView 和 this導(dǎo)致我的應(yīng)用程序崩潰,因?yàn)闊o(wú)法在圖像視圖上調(diào)用該方法.

This is an issue because I intend on retrieving the views with viewWithTag in the scrollViewDidEndDecelerating method and calling a method on the view, however whenever I try to retrieve a view with a tag of 0 I will retrieve one of the UIImageView's and this causes my app to crash because the method cannot be called on an image view.

我知道一種解決方法是將我的 GridView 存儲(chǔ)在一個(gè)單獨(dú)的實(shí)例數(shù)組中并從那里引用它們.但我很想知道這 2 個(gè) UIImageView 是什么以及它們是如何到達(dá)那里的.

I know a way round this is to store my GridViews in a seperate instance array and reference them from there. But I'm curious to know what the 2 UIImageViews are and how they got there.

推薦答案

UIScrollView 默認(rèn)包含 2 個(gè) UIImageViews 作為滾動(dòng)指示器的子視圖.雖然我在文檔中找不到任何關(guān)于滾動(dòng)指示器實(shí)現(xiàn)的具體信息,但這些圖像視圖存在于類聲明中(參見(jiàn) UIScrollView.h 標(biāo)頭):

UIScrollView by default contains 2 UIImageViews as subviews for scroll indicators. Although I can't find anything specific about scroll indicators implementation in docs, those imageviews are present in class declaration (see UIScrollView.h header):

UIKIT_CLASS_AVAILABLE(2_0) @interface UIScrollView : UIView <NSCoding> {
    ...
    UIImageView* _verticalScrollIndicator;
    UIImageView* _horizontalScrollIndicator;

您也可以不從 0 開(kāi)始分配標(biāo)簽,而是從某個(gè)正數(shù)開(kāi)始 - 這樣可以避免與標(biāo)準(zhǔn)子視圖發(fā)生沖突

You can also start assigning tags not from 0, but from some positive number - that way avoiding collision with standard subviews

這篇關(guān)于UIScrollView 幻象子視圖的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設(shè)置滾動(dòng)視圖內(nèi)容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動(dòng)滾動(dòng))
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運(yùn)行時(shí),使用 iOS 6.0 SDK 并為 iOS 5 Target 構(gòu)建會(huì)導(dǎo)致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創(chuàng)建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 91精品在线播放 | 久久男人 | 一区二区三区免费 | 国产精品精品视频一区二区三区 | 一区二区在线不卡 | 午夜精品福利视频 | 欧美色综合一区二区三区 | 一区二区三区精品 | 日韩精品一区中文字幕 | www97影院| 亚洲国产一区二区视频 | 精品国产一区二区久久 | 国产成人精品一区 | 色综合久久久 | 四虎影视免费观看 | 久久久精| 日韩一级免费大片 | 国产福利资源在线 | www.99热.com| 欧美老妇交乱视频 | 亚洲美女一区 | 午夜丁香视频在线观看 | 少妇一级淫片免费播放 | av大片| 激情 一区 | 国产成人久久精品 | 日韩国产精品一区二区三区 | www.日韩av.com| 亚洲精品一区中文字幕乱码 | 成人免费小视频 | 天天干成人网 | 国产精品99久久久久久大便 | 亚洲免费精品 | 久久久不卡网国产精品一区 | 盗摄精品av一区二区三区 | 四虎影视一区二区 | 国产96在线| a亚洲精品 | 成人国产精品久久 | 国产精品毛片一区二区在线看 | 久久青|