保存触摸点位置坐标

时间:2013-10-25 04:41:10

标签: ios iphone objective-c uiwebview uigesturerecognizer

我有显示UIWebView文章页面的HTML。我使用UILongPressGesture获取触摸位置坐标。我需要将此坐标保存到NSUserDefaults或任何地方,稍后再将其用于其他用途。如何保存这些触摸位置坐标

-(void)viewDidLoad{

UILongPressGestureRecognizer *tap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tapTest:)];
    [tap setDelegate:self];
    [wbCont.scrollView addGestureRecognizer:tap];

}


- (void)tapTest:(UILongPressGestureRecognizer *)sender {
    NSLog(@"coordinate is %f %f", [sender locationInView:wbCont].x,  [sender locationInView:wbCont].y);

}


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

2 个答案:

答案 0 :(得分:2)

适用于NSUserDefaults

中的商店位置
  - (void)tapTest:(UILongPressGestureRecognizer *)sender 
    {
        NSLog(@"coordinate is %f %f", [sender locationInView:wbCont].x,  [sender locationInView:wbCont].y);

    CGFloat x = [sender locationInView:wbCont].x;
    CGFloat y = [sender locationInView:wbCont].Y;

      NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
      [userDefaults setFloat:x forKey:@"xPoint"];
      [userDefaults setFloat:y forKey:@"yPoint"];
      [userDefaults synchronize];

    }

NSUserDefaults

检索点
NSUserDefaults *data = [NSUserDefaults standardUserDefaults];  
float xValue = [data floatForKey:@"xPoint"];
float yValue = [data floatForKey:@"yPoint"];

答案 1 :(得分:0)

您可以从用户默认设置中获取它以供将来使用。

 -(void)tapTest:(UILongPressGestureRecognizer *)sender
 {
  NSLog(@"coordinate is %f %f", [sender locationInView:wbCont].x,  [sender locationInView:wbCont].y);

 [[NSUserDefaults standardUserDefaults]setValue:[sender locationInView:wbCont].x forKey:@"xCor"];
   [[NSUserDefaults standardUserDefaults]setValue:[sender locationInView:wbCont].y forKey:@"yCor"];
 [[NSUserDefaults standardUserDefaults]synchronize];

  }