나는 배열에 UIImageView
객체를 감지하고 추가 할 수없는 몇 가지 뷰 문제를 다루고 있을지도 모른다. 나는 정말로 약간의 제안을 사용할 수있다.UIImageView 객체를 NSMutableArray에 UIView에 추가하기
은 내가 UIViewController
위에 앉아 UIView
에 연결된 이미지와 UIImageViews
의 숫자를합니다 (UIView
이 drawRect
및 몇 가지 추가 이점을 돕기 위해 추가 된) 있어요. 따라서 이미지를 터치하고 드래그 앤 드롭하면 해당 이미지를 삭제할 때 배열에 추가하고 싶습니다. 나는이 (가) touchesMoved
와 주변 UIImageView
그리고 마지막으로, '드롭'드래그
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self]; //can't use self.view in a UIView, this may be causing issues?
startLocation = location; // for reference as needed
NSLog(@"Image x coord: %f", location.x);
NSLog(@"Image y coord: %f", location.y);
if ([touch view] == obiWan_Block)
{obiWan_Block.center = location;}
else if ([touch view] == r2d2_Block)
{r2d2_Block.center = location;}
else if ([touch view] == you_Block)
{you_Block.center = location;}
}
을 다음 : 내 touchesBegan
는 UIImageView
터치되고있는 터치와 검사의 위치를 가져옵니다 후 다음과 같이 해당 뷰 중심으로 이미지는 touchesEnded
입니다. UIImageView
이 화면의 특정 영역에 드롭되면 특정 위치로 스냅합니다. 이 시점에서 배열에이 UIImageView
을 배치하고 싶지만 행운이 없습니다. 나는 여러 가지 견해가 만져지고 무엇이 addObject
을 통해 나의 NSMutableArray
에 추가되는지 혼란 스럽다. 아니면 뭔가를 완전히 놓칠 수도 있습니다.
NSLog(@"the quote array contains %d items. Contents = %@",[quoteArray count], quoteArray);
로그는 항상 말한다 :
이인용 배열이 0 항목을 포함 나는 다음과 같이
addObject
가 작동하는지 확인하기 위해NSLog
문이-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:self]; UIView *temp = [touch view]; UIImageView *currentImageView = (UIImageView *)[touch view]; //DON'T THINK THIS IS RIGHT NSLog(@"Current Image View is: %@", currentImageView); if ((location.x > dropZone.origin.x) && (location.y >= dropZone.origin.y) && ([touch view] != NULL)) { CGRect frame = temp.frame; if (touchCount == 0) { frame.origin.x = 15; frame.origin.y = 180; temp.frame = frame; [quoteArray addObject: currentImageView]; touchCount++; } else if (touchCount == 1) { frame.origin.x = 70; frame.origin.y = 180; temp.frame = frame; [quoteArray addObject: currentImageView]; touchCount++; } ....
: 여기 내
touchedEnded
방법입니다 . 내용 = (null)
감사합니다.
감사! 실제로 잘못된 장소에서 NSMutableArray를 초기화하고있었습니다. 문제를 해결하는 데 몇 시간이 걸리는 것은 항상 간단한 일입니다! :-) – jeffjohn01