限制

2011-09-19 51 views
0

我在application.The對象創建UIView三角形對象外視圖對象的運動,我可以能夠在屏幕上任意位置拖動,但我想,當它到達邊界region.So它不能去限制對象移動超越邊界。限制

我該怎麼能這樣做呢?

回答

1

UIView三角形對象的框架具有一箇中心和原點。當您移動/拖動對象時,您必須根據touchesMoved:等中計算的距離設置此框架。現在您所要做的就是在更改您的三角形物體的框架時進行檢查,例如:

if((yourView.frame.origin.x + yourView.frame.bounds.x)<=320 && yourView.frame.origin.x>=0 && (yourView.frame.origin.y + yourView.frame.bounds.y)<=480 && yourView.frame.origin.y>=0) 
//set your frame 
else //do nothing