Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将元素拖动到图像视图中。使用NSMutableArray_Iphone_Objective C_Xcode_Ios5 - Fatal编程技术网

Iphone 将元素拖动到图像视图中。使用NSMutableArray

Iphone 将元素拖动到图像视图中。使用NSMutableArray,iphone,objective-c,xcode,ios5,Iphone,Objective C,Xcode,Ios5,.m self.elements=[myElements getElements]; imagesElements = [[NSMutableArray alloc]init]; for(ElemetsList *item in self.elements) { UIImageView *oneelement = [[UIImageView alloc] initWithImage:[UIImage imageNamed:item.imgElement]]; o

.m

self.elements=[myElements getElements];

imagesElements = [[NSMutableArray alloc]init];
for(ElemetsList *item in self.elements)
{
        UIImageView *oneelement = [[UIImageView alloc] initWithImage:[UIImage imageNamed:item.imgElement]];
        oneelement.frame = CGRectMake(item.positionX, item.positionY, item.width, item.height);
        oneelement.userInteractionEnabled=YES;
        [imagesElements addObject:oneelement];
}

for(UIImageView *img in imagesElements) 
    [self.view addSubview:img];
然后我尝试与元素交互:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];

    for(UIImageView *img in imagesElements) 
    {  
        if([self view] == img)
        {
            CGPoint location = [touch locationInView:self.view];
            img.center=location;
        }
    }
}
但是“如果([自我视图]==img)”总是“否”。因此,图元不会拖动。
如果项目在数组中,如何拖放它们?

当您添加图像视图时,您会使它们成为
self.view
子视图,因此您需要测试
img
是否在
子视图
数组中。它不能等于包含它的视图。

这一行的主要用途是什么<代码>用于(UIImageView*imagesElements中的img)[self.view addSubview:img]谢谢您的回复!但如何正确地做到这一点呢?如果我在uberayu touchmoved中扫描一个项目,元素将被移动