2013-06-27 55 views
1

我有一個UIImageView,可以通過拖動它在我的視圖中移動。 UIImageView包含在我的主UIView中。我試圖確定的是用戶停止拖動後UIImageView的中心點(CGPoint)。我有以下代碼:嘗試在iOS中移動後尋找UIImageView的新中心點

CGRect frame = _imageView.frame; 
CGPoint newCenterPoint = _imageView.center; 

NSLog(@"The old center point for the UIImageView is: %@", NSStringFromCGPoint(newCenterPoint)); 

newCenterPoint.x = frame.origin.x + frame.size.width/2; 
newCenterPoint.y = frame.origin.y + frame.size.height/2; 

NSLog(@"The new center point for the UIImageView is: %@", NSStringFromCGPoint(newCenterPoint)); 

用我上面的代碼,我注意到newCenterPoint的值沒有更新。任何人都可以看到它是什麼,我做錯了,我能做些什麼來找到用戶完成移動後的UIImageView的中心?

在此先感謝所有回覆的人。

回答

1

當您完成移動視圖後,framecenter屬性都已更新。所以你不需要做任何計算,你只需要讀取數值。

你的代碼是打印中心的新值,然後從框架計算中心。他們應該是同樣的事情。