如何绑定 uiimagegview 在特定部分移动
我正在开发一个应用程序,在该应用程序中,我一次又一次地在按钮上添加相同的图像,单击随机位置并移动这些图像。
但是在移动这些图像时,图像可以在整个视图中移动,尽管在 UIView 中移动,我希望我的图像仅在我添加它的子视图(UIImage 视图)中移动。
这是我的 TouchesMoved 代码
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
UIImageView *imgPimple;// = [[UIImageView alloc]init];
imgPimple = (UIImageView*)[touch view];
CGPoint touchLocation = [touch locationInView:imgPimple superview];
if ([touch.view isKindOfClass:[UIImageView class]])
{
imgPimple.center = touchLocation;
}
}
I am working on an application in which I am adding the same image again and again on a button click on random positions and moving those images.
But on moving those images, images can move in whole view inspite of moving in UIView i want my image to move only in subview(UIImage view) on which i am adding it.
here is my code of TouchesMoved
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
UIImageView *imgPimple;// = [[UIImageView alloc]init];
imgPimple = (UIImageView*)[touch view];
CGPoint touchLocation = [touch locationInView:imgPimple superview];
if ([touch.view isKindOfClass:[UIImageView class]])
{
imgPimple.center = touchLocation;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该做的是:
我认为。
在我看来,如果您决定在其超级视图中将其移动到何处,并且在 imgPimple 视图中获取触摸位置,那么它将表现不正确。
What you should be doing is:
I think.
It seems to me that if you're deciding where to move it in its superview, and you get the touch location in the imgPimple view, it will behave incorrectly.