Xcode 双击可使用UIScrollView进行缩放
我正在使用苹果的源代码。我敢肯定,这只是我弄糟的一个片段。我有一个通过编程制作的表单。当我双击识别器时,它会启动并进行动作,但实际上它不会缩放。有什么建议吗?谢谢你的帮助Xcode 双击可使用UIScrollView进行缩放,xcode,uiscrollview,zooming,uigesturerecognizer,Xcode,Uiscrollview,Zooming,Uigesturerecognizer,我正在使用苹果的源代码。我敢肯定,这只是我弄糟的一个片段。我有一个通过编程制作的表单。当我双击识别器时,它会启动并进行动作,但实际上它不会缩放。有什么建议吗?谢谢你的帮助 imageScrollView.delegate=self; CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame]; imageScrollView=[[UIScrollView alloc]initWithFrame:fullScreenRect];
imageScrollView.delegate=self;
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
imageScrollView=[[UIScrollView alloc]initWithFrame:fullScreenRect];
imageScrollView.contentSize=CGSizeMake(750,1250);
imageScrollView.minimumZoomScale=1.0;
imageScrollView.maximumZoomScale=5.0;
[imageScrollView setZoomScale:imageScrollView.minimumZoomScale];
self.view=imageScrollView;
[imageScrollView release];
向scrollview添加了一组UItextfields/标签。
aircraftType=[[UITextField alloc]initWithFrame:CGRectMake(170,32,150,15)];
aircraftType.font=[UIFont systemFontOfSize:10];
aircraftType.borderStyle=UITextBorderStyleRoundedRect;
aircraftType.placeholder=@“Aicraft Type”;
aircraftType.delegate=自身;
[self.view addSubview:aircraftType]
#pragma mark UIScrollViewDelegate methods
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [imageScrollView viewWithTag:ZOOM_VIEW_TAG];
}
#pragma mark TapDetectingImageViewDelegate methods
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
// double tap zooms in
float newScale = [imageScrollView zoomScale] * ZOOM_STEP;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
[imageScrollView zoomToRect:zoomRect animated:YES];
}
#pragma mark Utility methods
- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center {
CGRect zoomRect;
// the zoom rect is in the content view's coordinates.
// At a zoom scale of 1.0, it would be the size of the imageScrollView's bounds.
// As the zoom scale decreases, so more content is visible, the size of the rect grows.
zoomRect.size.height = [imageScrollView frame].size.height / scale;
zoomRect.size.width = [imageScrollView frame].size.width / scale;
// choose an origin so as to get the right center.
zoomRect.origin.x = center.x - (zoomRect.size.width / 2.0);
zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0);
return zoomRect;
}