我想在其他图像上添加小剪贴画。iPhone:如何在其他图像上移动图像?
我知道我可以通过在背景imageView上添加其他imageView来做到这一点。
但我想移动(拖动)图像上的剪贴画。
是否还可以缩放剪贴画图像,如放大或缩小?怎么样?
我该怎么做?
我想在其他图像上添加小剪贴画。iPhone:如何在其他图像上移动图像?
我知道我可以通过在背景imageView上添加其他imageView来做到这一点。
但我想移动(拖动)图像上的剪贴画。
是否还可以缩放剪贴画图像,如放大或缩小?怎么样?
我该怎么做?
看看Gesture Recognizers:Apple提供了许多非常容易实现的“标准”手势。
这里的要点是,您将所需的手势识别器应用于剪贴画图像视图以提供拖动,调整大小等功能。
添加UIPanGestureRecognizer
到要拖动的ImageView:
UIGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:imageView action:@selector(pan:)];
[imageView addGestureRecognizer:panGesture];
[panGesture release];
然后,实施pan
法是这样的:
- (void)pan:(UIPanGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [recognizer translationInView:self.superview];
CGRect currentFrame = self.frame;
currentFrame.origin.x = self.frame.origin.x + translation.x;
currentFrame.origin.y = self.frame.origin.y + translation.y;
self.frame = currentFrame;
[recognizer setTranslation:CGPointZero inView:self.superview];
}
}
要缩放ImageView的,你可以添加一个UIPinchGestureRecognizer并根据需要缩放imageView。
你是否打算寻找解决方案? Stackoverflow和互联网都充满了解决方案。 -1 – vikingosegundo
我得到了缩放的解决方案,但无法找到拖动! :( – iPhone
看看苹果的MoveMe示例代码 - 那正是你想要的。 – Till