2011-11-22 73 views
-2

我想在其他圖像上添加小剪貼畫。iPhone:如何在其他圖像上移動圖像?

我知道我可以通過在背景imageView上添加其他imageView來做到這一點。

但我想移動(拖動)圖像上的剪貼畫。

是否還可以縮放剪貼畫圖像,如放大或縮小?怎麼樣?

我該怎麼做?

+2

你是否打算尋找解決方案? Stackoverflow和互聯網都充滿了解決方案。 -1 – vikingosegundo

+0

我得到了縮放的解決方案,但無法找到拖動! :( – iPhone

+1

看看蘋果的MoveMe示例代碼 - 那正是你想要的。 – Till

回答

1

看看Gesture Recognizers:Apple提供了許多非常容易實現的「標準」手勢。

這裏的要點是,您將所需的手勢識別器應用於剪貼畫圖像視圖以提供拖動,調整大小等功能。

1

添加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。

相關問題