1

我只是想将图像放入使用purelayout的主视图中的滚动视图中。

而我现在正在采取的是;

示例图像

请注意,红色背景的视图是滚动视图。而且图像不可滚动。

    - (void)loadView {
        self.view = [[UIView alloc] init];

        [self.scrollView addSubview:self.photoView];        
        [self.view addSubview:self.scrollView];
        [self.view setNeedsUpdateConstraints];
    }

    - (void)updateViewConstraints {

        if (!_didSetupConstraints) {
            ...
            ...
            ...
            [self.photoView autoPinEdgeToSuperviewEdge:ALEdgeTop];
            [self.photoView autoPinEdgeToSuperviewEdge:ALEdgeBottom];
            [self.photoView autoPinEdgeToSuperviewEdge:ALEdgeLeft];
            [self.photoView autoPinEdgeToSuperviewEdge:ALEdgeRight];

            self.didSetupConstraints = YES;
        }

        [super updateViewConstraints];
    }

    - (UIImageView *)photoView {
        if (!_photoView) {
            _photoView = [UIImageView newAutoLayoutView];
            _photoView.backgroundColor = [UIColor whiteColor];
        }
        return _photoView;
    }

    - (UIScrollView *)scrollView {
        if (!_scrollView) {
            _scrollView = [UIScrollView newAutoLayoutView];
            _scrollView.backgroundColor = [UIColor redColor];
            _scrollView.maximumZoomScale = 2.0;
            _scrollView.minimumZoomScale = 0.5;
        }
        return _scrollView;
    }
4

1 回答 1

0

好的,我所做的两个更改似乎效果很好。

首先,我手动设置 self.photoView 大小。

[self.photoView autoSetDimensionsToSize:CGSizeMake([HelperModel screenWidth], [HelperModel screenHeight] -[HelperModel viewHeight:self.navigationController.navigationBar] -20.0)];

助手模型.m

@implementation HelperModel

+ (CGFloat)screenWidth {
    return [[UIScreen mainScreen] bounds].size.width;
}

+ (CGFloat)screenHeight {
    return [[UIScreen mainScreen] bounds].size.height;
}

+ (CGFloat)viewHeight:(UIView *)view {
    return CGRectGetHeight(view.frame);
}

+ (CGFloat)photoDetailHeight {
    return [HelperModel screenHeight] -20;
}

@end   

第二,

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

对于缩放功能,如果缩放后​​的图像超出滚动视图的范围,则可以正确滚动图像。

于 2015-05-15T19:07:28.240 回答