objective-c - Objective-C : Zooming UIScrollView Properly

标签 objective-c ios uiscrollview

每当我缩放 View 时,我的 ScrollView 都会出现问题。 当我缩放 View 时,它会自动定位在左上角。我想要做的是 View 在移动后保持在原来的位置。

这是我的代码:

    mainSV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
    [mainSV setPagingEnabled:YES];
    [mainSV setDelegate:self];
    [mainSV setShowsVerticalScrollIndicator:NO];
    [mainSV setShowsHorizontalScrollIndicator:NO];
    [mainSV setScrollEnabled:YES];
    [mainSV setUserInteractionEnabled:YES];
    [mainSV setMaximumZoomScale:2.0];
    [mainSV setMinimumZoomScale:1.0];
    [mainSV setMultipleTouchEnabled:YES];
    [mainSV setClipsToBounds:YES];
    [mainSV setContentSize:CGSizeMake(768, 1024)];
    [self.view addSubview:mainSV];

    innerSV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
    [innerSV setPagingEnabled:YES];
    [innerSV setDelegate:self];
    [innerSV setShowsVerticalScrollIndicator:NO];
    [innerSV setShowsHorizontalScrollIndicator:NO];
    [innerSV setScrollEnabled:YES];
    [innerSV setUserInteractionEnabled:YES];
    [innerSV setClipsToBounds:YES];
    [innerSV setContentSize:CGSizeMake(768*numOfPages, 1024)];
    [mainSV addSubview:innerSV];

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)aScrollView {

    return innerSV;
}

InnerSV 也是一个 UIScrollView,它包含我的应用程序中的所有图像。

最佳答案

问题是由 innerSV ScrollView 分页造成的。 将其设置为 FALSE,它应该可以工作。

干杯!

关于objective-c - Objective-C : Zooming UIScrollView Properly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12853588/

相关文章:

ios - 使用AVPlayer播放时如何将音频连接到蓝牙

objective-c - 具有多个部分时使用 sectionIndexTitlesForTableView 进行索引

ios - UIScrollView : Not filling width of container? 内嵌套的 UIStackViews

ios - iOS 中的基本表达语言

objective-c - Objective-C 字典是有序容器吗?

iphone - 检查值是否为整数(Objective-C)

ios - 用几个数组分隔字符串数组

ios - 无法使用导航 Controller 锁定 View Controller 上的设备方向

ios - MKMapView 释放内存

xcode - 使用 Swift 在 UIScrollView 中居中图像