2012-09-24 39 views
3

我正在開發一個應用程序,它具有通過拖動右下角的按鈕來調整圖像大小並旋轉圖像視圖的功能。如何使用單個手指旋轉和調整圖像視圖的大小

我看到一個應用程序具有的功能,如果我們拖動右下角按鈕對角圖像視圖大小已調整大小,否則,如果我們拖動按鈕的左側或右側的方向imageview已按每個方向旋轉。我希望在我的應用程序中實現此功能

我正在努力實現單指旋轉以及調整圖像視圖的大小。

我可以通過拖動右下角的按鈕來成功實現調整圖像視圖的大小。但我沒有足夠的知識將旋轉添加到圖像視圖

請以正確的方式指導我。

我添加了下面的代碼,通過拖動它的右下角來調整圖像視圖的大小。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
UITouch *touch = [[event allTouches] anyObject]; 

    touchStart = [[touches anyObject] locationInView:imageView]; 
    isResizingLR = (containerVw.bounds.size.width - touchStart.x < kResizeThumbSize && containerVw.bounds.size.height - touchStart.y < kResizeThumbSize); 

} 



- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
CGPoint touchPoint = [[touches anyObject] locationInView:imageView]; 
CGPoint previous=[[touches anyObject]previousLocationInView:imageView]; 

UITouch *touch = [[event allTouches] anyObject]; 


float deltaWidth = touchPoint.x-previous.x; 
float deltaHeight = touchPoint.y-previous.y; 


    if (isResizingLR) { 
     containerVw.frame = CGRectMake(containerVw.frame.origin.x, containerVw.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth); 
     imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth);      
     dragIm.frame = CGRectMake(containerVw.frame.size.width-10, containerVw.frame.size.height-10,20,20); 


    if (!isResizingLR) { 
     containerVw.center = CGPointMake(containerVw.center.x + touchPoint.x touchStart.x,containerVw.center.y + touchPoint.y - touchStart.y); 
    } 
} 

enter image description here

+0

您如何期望僅從1點得到一個角度? – 2012-09-24 14:14:15

+0

我看到一個應用程序。他們已經實現了這個功能。我不知道他們是如何實現的。 – thavasidurai

+0

你有沒有得到解決方案? –

回答

9

我hitted相同的障礙是你的,所以我開發我自己的模塊ZDStickerView。這將是很好的參考。

首先,確保您的視圖的autoresizingMask應該靈活。

autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight 

否則調整大小將無法正常工作。

其次,我建議你使用「CGAffineTransformMakeRotation」和「ATAN2」功能來解決旋轉的問題,像這樣的:

float ang = atan2([recognizer locationInView:self.superview].y - self.center.y, 
         [recognizer locationInView:self.superview].x - self.center.x); 
    float angleDiff = deltaAngle - ang; 
    self.transform = CGAffineTransformMakeRotation(-angleDiff); 

第三,一定要相對使用協調,像這樣:

self.transform = CGAffineTransformMakeRotation(-angleDiff); 
+0

我玩ZDStickerView,它像一個魅力工作,我期待從你這樣的更多控制像這樣.. – thavasidurai

+0

@thavasidurai謝謝:-)如果您有任何ZDStickerView問題,給我一個問題由github。 – Kim

+0

太棒了!謝謝,你節省了我的時間! –

0

這可能會幫助,https://github.com/zedoul/ZDStickerView

帶OneFingerRotation,縮放,調整大小和關閉功能的IQStickerView。

特點:

  1. 單指旋轉縮放。
  2. 單指調整大小。
  3. 啓用/取消旋轉,縮放,使用屬性調整大小。
  4. 自動管理多個IQStickerView。
  5. 也可以使用UIScrollView。
  6. 快速響應。
相關問題