UIScrollView scrolls on all simulators but not on my iPhone

So, finding out how scrollView works, I implemented it with the following code:

self.scrollView.delegate = self;
self.scrollView.userInteractionEnabled = YES;
CGRect view = CGRectMake(0, 0, 320, 750);
self.scrollView.contentSize = view.size;

The above code works on all simulators in Xcode 6. However, when I run it on my phone (iphone4s on ios7), the scroll does not work at all. With the advent of new releases, do people face the same challenges? Or am I missing something I learned from the documentation?

+4
source share
3 answers

I have not tried answering Vishu, but I did an upgrade to iOS 8, so it is compatible with Xcode 6 and it will work!

-2
source

. scrollview viewDidLayoutSubviews, .

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    [scrollView setContentSize:CGSizeMake(320, 2600)];

    // Adjust frame for iPhone 4s
    if (self.view.bounds.size.height == 480) {
        scrollView.frame = CGRectMake(0, 0, 320, 436); // 436 allows 44 for navBar
    }
}
+2

AutoLayout

, Auto Layout , , . , , x- . .

UIScrollView , . , , , .

, . ( intrinsicContentSize, .) Auto Layout, , .

, subview float ( ) , , , .

, ,

, , .. translatesAutoresizingMaskIntoConstraints NO.

UIView , . , :

- (void)viewDidLoad {
UIView *contentView;



contentView = [[UIView alloc] initWithFrame:CGRectMake(0,0,contentWidth,contentHeight)];



[scrollView addSubview:contentView];

// contentView translatesAutoresizingMaskIntoConstraints, // YES;

// :

[scrollView setContentSize:CGSizeMake(contentWidth,contentHeight)];

/* ... */

}

, , , .

, , systemLayoutSizeFittingSize: ( UILayoutFittingCompressedSize), , , contentSize

, :

translatesAutoresizingMaskIntoConstraints NO . , . , , , . , , . viewDidLoad , , :

- (void)viewDidLoad {
UIScrollView *scrollView;
UIImageView *imageView;
NSDictionary *viewsDictionary;

// Create the scroll view and the image view.
scrollView  = [[UIScrollView alloc] init];
imageView = [[UIImageView alloc] init];

// Add an image to the image view.
[imageView setImage:[UIImage imageNamed:"MyReallyBigImage"]];

// Add the scroll view to our view.
[self.view addSubview:scrollView];

// Add the image view to the scroll view.
[scrollView addSubview:imageView];

// Set the translatesAutoresizingMaskIntoConstraints to NO so that the views autoresizing mask is not translated into auto layout constraints.
scrollView.translatesAutoresizingMaskIntoConstraints  = NO;
imageView.translatesAutoresizingMaskIntoConstraints = NO;

// Set the constraints for the scroll view and the image view.
viewsDictionary = NSDictionaryOfVariableBindings(scrollView, imageView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|" options:0 metrics: 0 views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|" options:0 metrics: 0 views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView]|" options:0 metrics: 0 views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView]|" options:0 metrics: 0 views:viewsDictionary]];

/* the rest of your code here... */
}
0

All Articles