gpt4 book ai didi

objective-c - iphone 应用程序 : drag drop UIImageView

转载 作者:行者123 更新时间:2023-11-28 23:08:28 25 4
gpt4 key购买 nike

我正在尝试在 iPhone 应用程序中执行拖放操作。我有一个包含多层 View 的主视图。

我放置了:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event    

在主视图中,但这不会被调用。当用户第一次触摸时,我可以在 View 上加载缩略图。我尝试拖动 UIImageView,但未调用 touchesMoved:

这是一些代码:(这是当用户触摸 View 时加载的拖动图像,它加载并放置在光标下方)

[dragImage addTarget:self action:@selector(endDrag) forControlEvents:UIControlEventTouchUpOutside];
[dragImage addTarget:self action:@selector(endDrag) forControlEvents:UIControlEventTouchUpInside];
[dragImage addTarget:self action:@selector(endDrag) forControlEvents:UIControlEventTouchDragInside];

最佳答案

这是我在屏幕上拖动图像的方法:

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[imageView_ addGestureRecognizer:panRecognizer];

然后:

-(void)move:(id)sender {

CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];

if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {

firstX = [[sender view] center].x;
firstY = [[sender view] center].y;
}

translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);
[[sender view] setCenter:translatedPoint];

}

关于objective-c - iphone 应用程序 : drag drop UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8813673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com