Why is UIScrollView leaving space on top and does

2019-01-09 03:14发布

I am new to objective-C programming.

I am using UIScrollView with some labels, image and text view on it.

I have turned off Autolayout and already tried with "Adjust scroll View Insets" on (situation described in title) and off (doesn't scroll).

This is what I insert into viewDidLoad:

    [scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 687)];

But I must be missing something very simple.

10条回答
Root(大扎)
2楼-- · 2019-01-09 04:05

iOS 11

if #available(iOS 11.0, *) {
    scrollView.contentInsetAdjustmentBehavior = .never
} else {
    automaticallyAdjustsScrollViewInsets = false
}
查看更多
Deceive 欺骗
3楼-- · 2019-01-09 04:06

Actually, the margin has nothing to do with ScrollViewInsets or contentOffset. It's just a conflict between SuperView.Top and SafeArea.Top pinning, happens when you pin the UIScrollView to top, bottom, left and right.

This is the right way to cover the top margin.

1) Pin all the four sides.

Pinning

2) Select the top constraint > Change Second Item to Superview.Top

conflict

3) Then the last step is to change the Constant to 0 (Zero). enter image description here

You might want to check this too: https://github.com/29satnam/MoveTextFieldWhenKeyboardAppearsSwift

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-09 04:07

iOS 11

In my case only changing this UIScrollView Content Insets property in IB from Automatic to Never helped.

查看更多
Animai°情兽
5楼-- · 2019-01-09 04:07

In your view .m file, use this code to fix this problem

-(void)layoutSubviews{
    // To fix iOS8 bug of scrollView autolayout
    if([[[[[UIDevice currentDevice]systemVersion] componentsSeparatedByString:@"."]objectAtIndex:0] integerValue] == 8){
        [self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
}
查看更多
登录 后发表回答