iphone - 如何将 CGPoint 存储在数组中

标签 iphone objective-c xcode cocoa-touch

您好,我正在尝试将移动点存储在 NSMutableArray 中,所以我尝试过这样的操作

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *move = [[event allTouches] anyObject];
    CGPoint MovePoint = [move locationInView:self.view];
if (MovePointsArray==NULL) {
        MovePointsArray=[[NSMutableArray alloc]init];
    }
    [MovePointsArray arrayWithObjects:[NSValue valueWithCGPoint:MovePoint]];
}

但这不起作用我如何将这些点存储在 NSMutableArray

最佳答案

你应该在最后一行使用 addObject:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *move = [[event allTouches] anyObject];
    CGPoint MovePoint = [move locationInView:self.view];
if (MovePointsArray==NULL) {
        MovePointsArray=[[NSMutableArray alloc]init];
    }
    [MovePointsArray addObject:[NSValue valueWithCGPoint:MovePoint]];
}

关于iphone - 如何将 CGPoint 存储在数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7688433/

相关文章:

ios - 从 API 模式问题加载数据

objective-c - 如何用来自两个不同对象类型的两个数组的数据填充 UITableView?

ios - AVPlayer 无法在 iOS 9 上播放

iphone - 使用 NSString 类型的表达式初始化 NSMutableString 的指针不兼容 - 警告

ios - 如何更新 UISegmentedControl

ios - 应用程序试图在 didSelectRowAtIndexPath 中将一个 nil View Controller 推送到目标上

ios - 如何在 XCode 中复制文件?

iphone - 更改 NavigationBar 颜色(背景颜色)

iphone - 可能优化卸载 UIScrollView 和 PageControl 中不再可见的 View + Controller

iphone - 如何在 iPhone 应用程序中查看 Google 文档已更改?