如何拖動UIImageView,但只能在屏幕的某個區域內操作?我的代碼目前看起來像這樣:在受限範圍內拖動UIImageView
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
touch.view.frame = CGRectMake(104, 171, 113, 49);
if([touch view] == toggle)
{
CGPoint location = [touch locationInView:self.view];
CGPoint newLocation = CGPointMake(toggle.center.x, location.y);
toggle.center = newLocation;
NSLog(@"%f \n",toggle.center.y);
}
}
我想只能在我定義的框架內拖動圖像。
即時通訊有點新手。你可以把它放到我的代碼中來展示給我看。我不太明白。 – Omar
它恰好在'toggle.center = newLocation;'之前,就像我寫的一樣。 – jtbandes
有沒有使用框架的另一種方式嗎? – Omar