我有显示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;
}
答案 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];
}