简体   繁体   English

UIScrollView子视图之间的差距

[英]Gap between subviews of UIScrollView

I have two subviews of UIScrollView. 我有两个UIScrollView子视图。 One is textView and other is tableView. 一个是textView,另一个是tableView。 I made textview's height flexible based on its content, but I have one problem. 我根据内容使textview的高度变得灵活,但我有一个问题。 If the text in the textview (which is parsed data) is small, there is a big gap between textview and tableview. 如果textview中的文本(解析数据)很小,则textview和tableview之间存在很大差距。 Or if the text is too large then it covers the tableview. 或者如果文本太大,那么它将覆盖tableview。 How can I keep the same gap between textview and tableview irrespective of the amount of content of text view? 无论文本视图的内容量多少,如何在textview和tableview之间保持相同的差距? This is all done in IB. 这一切都在IB中完成。 Thanks. 谢谢。

you must handle both textview and tableview position dynamically like ur text view height and y-axis is y-axis 10; 你必须动态处理textview和tableview位置,如你的文本视图高度和y轴是y轴10; height 40; 身高40; now in tableview setframe:cgrectmake(your X coordinate, textview.frame.size.height+20) 现在在tableview setframe中:cgrectmake(你的X坐标,textview.frame.size.height + 20)

so its always show same difference between textview and tableview if your textview height is 60 than tableview y point is 60+20 所以如果你的textview高度是60而不是tableview,那么它总是在textview和tableview之间显示相同的差异y点是60 + 20

- (void)loadView 
{    
    CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
    pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
    pagingScrollView.pagingEnabled = YES;
    pagingScrollView.backgroundColor = [UIColor blackColor];
    pagingScrollView.showsVerticalScrollIndicator = NO;
    pagingScrollView.showsHorizontalScrollIndicator = NO;
    pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width * [self imageCount],
                                              pagingScrollViewFrame.size.height);
    pagingScrollView.delegate = self;
    self.view = pagingScrollView;

}

- (CGRect)frameForPagingScrollView {
    CGRect frame = [[UIScreen mainScreen] bounds];
    frame.origin.x -= PADDING;
    frame.size.width += (2 * PADDING);
    return frame;
}

- (CGRect)frameForPageAtIndex:(NSUInteger)index {
    CGRect pagingScrollViewFrame = [self frameForPagingScrollView];

    CGRect pageFrame = pagingScrollViewFrame;
    pageFrame.size.width -= (2 * PADDING);
    pageFrame.origin.x = (pagingScrollViewFrame.size.width * index) + PADDING;
    return pageFrame;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM