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

UIScrollView 幻象子視圖

UIScrollView phantom subviews(UIScrollView 幻象子視圖)
本文介紹了UIScrollView 幻象子視圖的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 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 包含一個名為 gridScrollView 的滾動視圖,在 AnalysisView 實現文件中,我有一個將視圖作為子視圖添加到滾動視圖的方法:

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++;
}

我已將滾動視圖委托設置為 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]);
}

當 scrollViewDidEndDecelerating 方法觸發時,它報告子視圖的數量是 5.這些子視圖中的 3 個是我期望的 GridView.但是有 2 個 UIImageViews 我不知道它們為什么在那里.

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.

這是一個問題,因為我打算在 scrollViewDidEndDecelerating 方法中使用 viewWithTag 檢索視圖并在視圖上調用一個方法,但是每當我嘗試檢索標簽為 0 的視圖時,我都會檢索其中一個 UIImageView 和 this導致我的應用程序崩潰,因為無法在圖像視圖上調用該方法.

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 存儲在一個單獨的實例數組中并從那里引用它們.但我很想知道這 2 個 UIImageView 是什么以及它們是如何到達那里的.

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 默認包含 2 個 UIImageViews 作為滾動指示器的子視圖.雖然我在文檔中找不到任何關于滾動指示器實現的具體信息,但這些圖像視圖存在于類聲明中(參見 UIScrollView.h 標頭):

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 開始分配標簽,而是從某個正數開始 - 這樣可以避免與標準子視圖發生沖突

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

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

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

相關文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設置滾動視圖內容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
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 模擬器上運行時,使用 iOS 6.0 SDK 并為 iOS 5 Target 構建會導致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 午夜在线影院 | 亚洲激情另类 | 黑人精品一区二区 | 可以看毛片的网站 | 亚洲第一视频网站 | 日本a视频| 国产精品99久久久久久久久 | 超碰成人av| 久久99精品久久久久久国产越南 | 欧美在线亚洲 | 人人草人人草 | 午夜精品一区二区三区在线播放 | 亚洲日本国产 | 久久免费看视频 | 国产一区高清 | 在线免费观看av网站 | 国产免费一区二区三区免费视频 | 97在线免费 | 亚洲欧美日韩一区二区 | 日韩欧美自拍 | 91精品国产综合久久久久久 | 韩国三级av | 蜜桃精品一区二区 | 成人久久视频 | 精品国产一二三区 | 欧美夜夜操 | 天堂成人网| 福利视频网站 | 国产一区不卡 | 一个色综合网 | 久久久www成人免费精品 | 欧美顶级黄色大片免费 | 日本精品视频在线 | 国产欧美日韩一区 | 美利坚合众国av | 一级中国毛片 | 天天干天天看 | 国产日韩精品视频 | 国产成人区 | 精品一区二区三区视频 | 国产丝袜一区 |