Chúng tôi sẽ phát triển một dự án trong ios, Vì vậy, tôi đang học cách bố trí tự động với scrollview, Nó hoạt động tốt khi tôi thêm một hình ảnh, Khi tôi cố gắng để thêm nhiều hơn một hình ảnh, tôi đã có điều rất lạ hình ảnh đầu tiên đã được kéo dài và chồng chéo với hình ảnh rất tiếp theo. Đây là mã của tôiUIScrollView không hoạt động với Autolayout Lập trình (sử dụng nhiều ảnh)
UIScrollView *scrollView = [[UIScrollView alloc] init];
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImage:[UIImage imageNamed:@"2.png"]];
UIImageView *imageView1 = [[UIImageView alloc] init];
[imageView1 setImage:[UIImage imageNamed:@"01.png"]];
[self.view addSubview:scrollView];
[scrollView addSubview:imageView1];
[scrollView addSubview:imageView];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
imageView.translatesAutoresizingMaskIntoConstraints = NO;
imageView1.translatesAutoresizingMaskIntoConstraints = NO;
self.imageViewPointer = imageView;
self.imageViewPointer = imageView1;
scrollView.maximumZoomScale = 2;
scrollView.minimumZoomScale = .5;
scrollView.delegate = self;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(scrollView,imageView,imageView1);
NSLog(@"Current views dictionary: %@", viewsDictionary);
[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:|-20-[imageView]|" options:0 metrics: 0 views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-415-[imageView]|" options:0
metrics: 0 views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView1]-20-|" options:0 metrics: 0 views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView1]-150-|" options:0 metrics: 0 views:viewsDictionary]];
và tôi nhận được kết quả !!!
Nó đang làm việc, nhưng nó không phải là dễ dàng để thiết lập các ràng buộc. Ở đây bạn có chủ đề trùng lặp nơi nhiều người mô tả cách họ đã xử lý vấn đề này: http://stackoverflow.com/questions/20223021/i-am-officially-too-stupid-for-uiscrollview-with-autolayout – KlimczakM
Tôi sẽ khuyên bạn nên sử dụng thư viện PureLayout: https://github.com/smileyborg/PureLayout –
cảm ơn phản hồi của bạn, Xin lỗi tôi quên nói với nó "Tôi đang tìm kiếm nó theo chương trình". – nisar