2012-04-28 77 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