Iphone ui打开/关闭ui长按手势识别器的开关
我在我的应用程序中声明了以下方法,我想在我的mapView中实现一个开关来打开和关闭Iphone ui打开/关闭ui长按手势识别器的开关,iphone,ios6,uigesturerecognizer,uiswitch,Iphone,Ios6,Uigesturerecognizer,Uiswitch,我在我的应用程序中声明了以下方法,我想在我的mapView中实现一个开关来打开和关闭ui长按GestureRecognitizer - (IBAction)addNewPin:(UISwitch *)sender { if (sender.on) { NSLog(@"ON!!"); } else { NSLog(@"OFF!!"); } } - (IBAction)didPressForPin:(UILongPressGestureRecognizer *)sender { CG
ui长按GestureRecognitizer
- (IBAction)addNewPin:(UISwitch *)sender {
if (sender.on) {
NSLog(@"ON!!");
}
else {
NSLog(@"OFF!!");
}
}
- (IBAction)didPressForPin:(UILongPressGestureRecognizer *)sender {
CGPoint point = [sender locationInView:self.mapView];
CLLocationCoordinate2D locCoord = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
MKPointAnnotation *pa = [[MKPointAnnotation alloc]init];
pa.coordinate = locCoord;
pa.title = @"Test Title!";
[mapView addAnnotation:pa];
NSLog(@"Pressed!!");
}
我知道我可以添加或删除手势识别器或实现
。enabled=NO
,但我不知道如何在switch方法中实现它。假设您拥有LongPressGestureRecognitor
属性,类似的内容可能会有所帮助:
@synthesize longPressGestureRecognizer = _longPressGestureRecognizer;
- (UILongPressGestureRecognizer *)longPressGestureRecognizer
{
if (_longPressGestureRecognizer) {
return _longPressGestureRecognizer;
}
_longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
return _longPressGestureRecognizer;
}
- (IBAction)toggleAddPinSwitch:(UISwitch *)sender
{
if ([sender isOn]) {
[self.mapView addGestureRecognizer:self.longPressGestureRecognizer];
} else {
[self.mapView removeGestureRecognizer:self.longPressGestureRecognizer];
}
}
这个问题与“Xcode 4.5”有什么关系?你99%都在那里,我不确定你不知道该怎么做?谢谢,这很有效。我刚刚在ViewDidLoad中添加了“\u LongPressGestureRecognitizer=[[UILongPressGestureRecognitizer alloc]initWithTarget:self action:@selector(HandleLongPress手势:)];return _LongPressGestureRecognitizer;”,以便使用我的触摸定位方法。很高兴听到这个消息。快乐编码。