2012-04-28 78 views

回答

0

基本思想是:

  1. 創建一個新的臨時-的ImageView與所選圖像。
  2. 這在原始的ImageView的確切位置添加到窗口。
  3. 刪除original-ImageView(如果你願意的話)
  4. 移動/縮放屏幕上所需位置的temp-ImageView。
  5. 末的ImageView添加到藍色區域所需的位置。
  6. 刪除臨時-ImageView的。

你將不得不做一些計算用 - (的CGRect)convertRect:(的CGRect)RECT fromView:(UIView的*)查看 不能確定,但​​選擇器可以在不同的窗口比你的藍區奠定。

CGRect destRect; // position in window, height/width need to be flipped, so the size is correct after rotation 

// add a ContainerView so rotation-handling is easier, esp. durring moving/scaling 
UIView *containerView = [[UIView alloc] initWithFrame:destRect]; 

// set the frame of the imageView, origin 0/0 so rotation is easy to handle, height/width flipp back 
UIImageView *tempImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, destRect.size.height, destRect.size.width)]; 

// flip layer center as well 
[tempImageView setCenter:CGPointMake(camView.center.y, camView.center.x)]; 

// add the rotation 
[tempImageView setTransform:CGAffineTransformMakeRotation(M_PI_2)]; 

[tempImageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; 
+0

嘛。我其實是這樣做的。但現在的問題是: 1.my應用程序是橫向模式 2.當我臨時-的ImageView添加到Windows,臨時-ImageView的具有旋轉效果,這使得它看起來是正確的縱向模式中而不是在橫向模式,那不是我的預期。你能解決這個問題嗎? – 2012-04-28 09:14:55

+0

您的應用程序是否始終處於橫向模式?如果是的話,很容易只需添加一個硬編碼的90度旋轉到temp-ImageView的,否則你必須評估設備的方向。我將添加一些處理旋轉的代碼片段到我的帖子。 – 2012-04-28 09:29:58

+0

感謝您的幫助。這絕對有效。但你知道,這個解決方案只是有點乏味,不夠優雅。有什麼更好的主意? – 2012-04-28 09:59:43