我猜它是重复的问题,但我已经检查了有关stackoverflow的所有信息,我无法弄明白。
在zooming
的图片中UICollectionViewCell
后,我想平移图片,但只到UIScreen
/父视图的边框。
这就是发生的事情:
这是我用于Scaling
&的代码。 Pan
:
- (void)moveImage:(UIPanGestureRecognizer *)recognizer
{
if (self.pinchGesture.scale<1.0){
return;
}
if (recognizer.state == UIGestureRecognizerStateBegan || recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [recognizer translationInView:self.superview];
CGPoint newcenter = CGPointMake(self.center.x + translation.x, self.center.y + translation.y);
[self setCenter:newcenter];
[recognizer setTranslation:CGPointZero inView:self];
}
}
- (void)doPinch:(UIPinchGestureRecognizer *)gesture
{
if([gesture state] == UIGestureRecognizerStateBegan) {
previousScale = 1.0;
}
CGFloat currentScale = [[self.layer valueForKeyPath:@"transform.scale"] floatValue];
// Constants to adjust the max/min values of zoom
const CGFloat kMaxScale = 4.0;
const CGFloat kMinScale = 1.0;
CGFloat newScale = 1 - (previousScale - [gesture scale]); // new scale is in the range (0-1)
newScale = MIN(newScale, kMaxScale / currentScale);
newScale = MAX(newScale, kMinScale / currentScale);
self.transform = CGAffineTransformScale(self.transform, newScale, newScale);
}
提前致谢;)
答案 0 :(得分:1)
最后我使用实现UIScrollView
的缩放。我在UIScrollView
添加了UICollectionViewCell
。
我已将其设置为minimumZoomScale
的{{1}},maximumZoomScale
,zoomScale
,并实施了UIScrollView
viewForZoomingInScrollView
方法在我的自定义UIScrollViewDelegate
上,以便在UICollectionViewCell
中运行zoom
功能。
这就是我UIScrollView
的{{1}}:方法:
cellForItemAtIndexPath