1

我有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;
}
4

2 回答 2

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"];
于 2013-10-25T04:53:39.467 回答
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];

  }
于 2013-10-25T04:48:03.110 回答