2

我有一个 UIScrollView,UIView里面有一个,在里面UIView我做了一个按钮来添加textLabels它。理想情况下,我想要一个非常大的画布,并且能够在上面放置文本并平移和缩放。但是UIScrollView它确实缩放,但根本不平移

似乎当我删除我在UIView其中添加的内容时,UIScrollView它工作正常。

继承人 viewDidLoad:

[super viewDidLoad];

CGFloat mainViewWidth = 700;
CGFloat mainViewHeight = 500;

//scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height * kNumberOfPages);
//self.mainScrollView.bounds = CGRectMake(0., 0., 3000, 3000);
self.mainScrollView.scrollsToTop = NO;
self.mainScrollView.delegate = self;
self.mainScrollView.maximumZoomScale = 50.;
self.mainScrollView.minimumZoomScale = .1;
self.mainScrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight;


self.mainView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, mainViewWidth, mainViewHeight)];
[self.mainView setUserInteractionEnabled:NO];
self.mainView.backgroundColor = [[UIColor alloc] initWithRed:0.82110049709463495
                                                        green:1
                                                        blue:0.95704295882687884
                                                        alpha:1];


[self.mainScrollView setContentSize:CGSizeMake(5000, 5000)];
[self.mainScrollView insertSubview:self.mainView atIndex:0];

编辑:继承人所有我为 UIScrollViewDelegate

#pragma mark - Scroll View Delegate
- (void)scrollViewDidScroll:(UIScrollView *)sender {

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    //
    return self.mainView;
}


- (void)scrollViewDidEndZooming:(UIScrollView *)zoomedScrollView withView:(UIView *)view atScale:(float)scale
{

}
4

1 回答 1

2

我刚刚经历了同样的困境。

我的 UIScrollView 存在于情节提要中,如果我将该情节提要中的 UIView ( containerView) 添加到 UIScrollView,则图像无法平移。各种其他的居中怪异也发生了。

但如果我通过代码做到这一点:

// Set up the image we want to scroll & zoom
UIImage *image = [UIImage imageNamed:@"plan-150ppi.jpg"];
self.imageView = [[UIImageView alloc] initWithImage:image];

self.containerView = [[UIView alloc] initWithFrame:self.imageView.frame];
[self.containerView addSubview:self.imageView];
[self.scrollView addSubview:self.containerView];

// Tell the scroll view the size of the contents
self.scrollView.contentSize = self.containerView.frame.size;

...然后它工作得很好。

于 2014-11-29T22:45:32.527 回答