Ios 使用UIScrollView滚动UIImage
我正试图让我的图像可以Ios 使用UIScrollView滚动UIImage,ios,uiscrollview,uiimageview,Ios,Uiscrollview,Uiimageview,我正试图让我的图像可以平移和缩放,但我似乎无法让它工作 这是我的注释代码>创建UIScrollView>创建PFImageView(UIImage)>将图像添加到UIScrollView>获取和显示图像 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSLog(@"%@",_courseObject);
平移
和缩放
,但我似乎无法让它工作
这是我的注释代码>创建UIScrollView
>创建PFImageView
(UIImage
)>将图像添加到UIScrollView
>获取和显示图像
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"%@",_courseObject); //checking object has loaded
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = self.view.bounds; //scroll view occupies full parent view!
scrollView.contentSize = CGSizeMake(400, 800); //scroll view size
scrollView.showsVerticalScrollIndicator = YES; //to hide scroll indicators!
scrollView.showsHorizontalScrollIndicator = YES; //by default, it shows!
scrollView.scrollEnabled = YES; //say "NO" to disable scroll
[self.view addSubview:scrollView]; //adding to parent view!
PFImageView *mapImage = [[PFImageView alloc] init]; //create imageview
mapImage.frame = self.navigationController.view.frame; //set image boundaries to fill nav frame(!)
mapImage.image = [UIImage imageNamed:@"loading"]; //placeholder image
mapImage.file = (PFFile *)[_courseObject objectForKey:@"file"]; //retrieve the map image
[scrollView addSubview:mapImage]; //add the mapImage to scrollView
[mapImage loadInBackground]; //retrieve image and add
}
您需要使用滚动视图委托,更具体地说,您需要实现以下方法:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
(PFImageView*mapImage必须成为属性而不是局部变量)
这里的问题是scrollView.contentSize不够大,因此当尝试滚动时,它没有拾取移动 通过更改值以填充帧以及实现委托协议,我可以使用滚动视图
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];