gpt4 book ai didi

iphone - UIScrollView 缩放后无法平移

转载 作者:行者123 更新时间:2023-12-03 19:28:23 25 4
gpt4 key购买 nike

我似乎在这里实现了所有正确的代码。我的代码中是否缺少某些内容?

//
// ScrollyiPadViewController.m
// ScrollyiPad
//
// Created by Sidwyn Koh on 5/19/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "ScrollyiPadViewController.h"

@implementation ScrollyiPadViewController

-(void)viewDidLoad{
[self.view addSubview:scrollView];
[scrollView addSubview:imageView];

UIImage *image = [UIImage imageNamed:@"hardware-01-20100127.jpg"];
scrollView.contentSize = [image size];
scrollView.maximumZoomScale = 2.0;
// scrollView.delegate = self;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return imageView;
}



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[super dealloc];
}

@end

最佳答案

我也经历过类似的事情;缩放后平移将停止工作。发现在委托(delegate)函数“scrollViewDidEndZooming:withView:atScale:”中,我需要根据传递的“atScale”更新 ScrollView 的 contentsize 属性。

类似于:self.scrollView.contentSize = CGSizeMake(self.imageView.image.size.width*scale, self.imageView.image.size.height*scale);

self.imageView.frame 相对于缩放比例自动更新;所以你不需要根据比例调整框架。

如果没有明确设置scrollView的contentsize;然后它就被分配了 imageView 帧大小...这就是使 imageView 不可滚动的原因。

关于iphone - UIScrollView 缩放后无法平移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3467812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com