NSUserDefaults-保存UIImageView位置 [英] NSUserDefaults - Saving UIImageView Position

查看:114
本文介绍了NSUserDefaults-保存UIImageView位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个UIImageView和一个UIButton. UIImageView具有UIPanGestureRecognizer,并且可以在屏幕上拖动.我写过:

In my application, I have a UIImageView and a UIButton. The UIImageView has a UIPanGestureRecognizer, and can be dragged around the screen. I have written:

int defaultBallLocation = ball.center; 在我的- (IBAction)saveButton

并且Xcode说无法将CGPoint与int关联".

and Xcode is saying "Cannot associate CGPoint with int".

那么,如何通过按保存"在屏幕上保存球(UIImageView)的位置,然后通过NSUserDefaults按加载"来加载保存的位置?我以前使用过NSUserDefaults,但仅使用过UISegmentedController.谢谢!

So, how can I save the ball (UIImageView) position on the screen by pressing "save", then load the saved position by pressing "load" through NSUserDefaults? I have worked with NSUserDefaults before, but only with a UISegmentedController. Thanks!

推荐答案

另一个选项,您可以将其存储为字符串:

Another option, you can store it as string:

NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
// Set
[userDefaults setObject:NSStringFromCGPoint(yourPoint) forKey:@"pointPosition"];
// Save
[userDefaults synchronize];
// Get
CGPoint thePoint = CGPointFromString([userDefaults objectForKey:@"pointPosition"]);

这篇关于NSUserDefaults-保存UIImageView位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆