久久久久久久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 可縮放?)
主站蜘蛛池模板: 亚洲黄色一区二区三区 | 91资源在线 | 91精品中文字幕一区二区三区 | 免费一级黄 | 久久久久中文字幕 | 亚洲精品一区二区三区免 | 黄色免费观看网站 | 日本天天操| 国产精品成人av | 久久这里只有精品首页 | 亚洲网址在线观看 | 日本三级全黄三级三级三级口周 | 日韩在线不卡 | 国产一级免费视频 | 精品成人佐山爱一区二区 | 久久精品免费观看 | 午夜视频在线观看网址 | 在线看av网址 | 国产在线一区二区三区 | 亚洲自拍偷拍免费视频 | 午夜资源 | 九九热九九 | 精品二区视频 | 少妇一区在线观看 | 国产精品欧美一区二区三区不卡 | 国产精品入口久久 | 国产1区 | 黄色免费在线观看网址 | 欧美黄色精品 | 午夜免费看 | 日本久久精品 | 久久无毛 | 欧美日韩国产精品激情在线播放 | 高清国产午夜精品久久久久久 | 在线观看视频一区 | 国产精品久久久久久久久久软件 | 精品视频在线观看 | 99精品久久久 | 久在线视频 | 精品网站999www | 国产激情在线观看 |