长按每次轻按会掉落 2 个引脚
我让我的应用程序通过长按来删除引脚,我只允许用户删除两个引脚,我猜它可以工作..但是每次我点击在模拟器中添加一个引脚时,它都会添加两个引脚(不仅仅是一个)..这是代码:
-(void) handleLongPressGesture:(UIGestureRecognizer*)sender
{
if (pinId < 3) {
// Here we get the CGPoint for the touch and convert it to
// latitude and longitude coordinates to display on the map
CGPoint point = [sender locationInView:self.mapView];
CLLocationCoordinate2D coord = [self.mapView convertPoint:point
toCoordinateFromView:self.mapView];
if (pinId == 1) {
lat1 = coord.latitude;
long1 = coord.longitude;
MapAppAnnotation* annotation;
annotation = [[MapAppAnnotation alloc] initWithCoordinate:coord
andID:pinId];
[mapView addAnnotation:annotation];
MKCircle* circle = [MKCircle circleWithCenterCoordinate:coord
radius:5000];
[mapView addOverlay:circle];
pinId++;
} else {
lat2 = coord.latitude;
long2 = coord.longitude;
MapAppAnnotation* annotation2;
annotation2 = [[MapAppAnnotation alloc] initWithCoordinate:coord
andID:pinId];
[mapView addAnnotation:annotation2];
}
}
}
我想知道是否是我的错(代码错误..)或者是iPhone模拟器让我的长鼠标压力像两个不同的长压力一样..这可能吗?
I got my app dropping pin by long tap, i allow users to drop only two pins and its working i guess.. but every time i tap to add a pin in the simulator it adds two pins (not only one).. here is the code:
-(void) handleLongPressGesture:(UIGestureRecognizer*)sender
{
if (pinId < 3) {
// Here we get the CGPoint for the touch and convert it to
// latitude and longitude coordinates to display on the map
CGPoint point = [sender locationInView:self.mapView];
CLLocationCoordinate2D coord = [self.mapView convertPoint:point
toCoordinateFromView:self.mapView];
if (pinId == 1) {
lat1 = coord.latitude;
long1 = coord.longitude;
MapAppAnnotation* annotation;
annotation = [[MapAppAnnotation alloc] initWithCoordinate:coord
andID:pinId];
[mapView addAnnotation:annotation];
MKCircle* circle = [MKCircle circleWithCenterCoordinate:coord
radius:5000];
[mapView addOverlay:circle];
pinId++;
} else {
lat2 = coord.latitude;
long2 = coord.longitude;
MapAppAnnotation* annotation2;
annotation2 = [[MapAppAnnotation alloc] initWithCoordinate:coord
andID:pinId];
[mapView addAnnotation:annotation2];
}
}
}
I would like to know if is my fault (code error..) or is the iPhone simulator that get my long-mouse-pressure like two different long pressures.. is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当手势开始时,您的选择器将被调用一次,当手势结束时,您的选择器将被调用一次。检查手势的状态并对相关手势进行操作。
UILongPressGestureRecognizer 的类参考说:
Your selector is being called once when the gesture begins, and again when it ends. Check the gesture's state and act on the relevant one.
The class reference for UILongPressGestureRecognizer says: