簡體   English   中英

錯誤的UIScrollView子視圖放置

[英]Wrong UIScrollView subviews placement

我正在以編程方式創建我的應用程序的用戶界面,並且已經將這個問題困擾了近兩天。

我有我的MasterViewController創建我的scrollview的實例:

CGRect bottomViewFrame = CGRectMake(0,self.view.bounds.size.height-self.view.bounds.size.height/4.6,self.view.frame.size.width,100);
BottomView *bottomView = [[BottomView alloc] initWithFrame:bottomViewFrame];

在我的ScrollView的initWithFrame:方法中,我有:

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];

    self.backgroundColor = [UIColor blackColor];
    self.contentSize = CGSizeMake(self.bounds.size.width, self.bounds.size.height);
    self.showsVerticalScrollIndicator = NO;
    self.pagingEnabled = YES;

    UIView* test = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    test.backgroundColor = [UIColor redColor];

    [self addSubview:test];

    return self;
}

有些事情不能正常運行...首先,您可以看到我將ScrollView的contentSize高度設置為它自己的高度,但是在模擬器上執行后我仍然可以滾動。

其次,我將UIView“ Test”的原點設置為(0; 0),但它在我看來像(0; self.frame.height / 2)的某些坐標處顯示。

這是模擬器上的最終結果

在此處輸入圖片說明

有人知道嗎? 在此先感謝,非常感謝。

解決了! 經過兩天的奮斗,我終於得到了答案。 UINavigationController讓MainViewController自動設置UIScrollView的子視圖插圖,您只需要將其插入到MasterViewController的init方法中即可

self.automaticallyAdjustsScrollViewInsets = NO;

解決問題,讓我的觀點隨心所欲。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM