나는 그림을 드래그 할 새로운 게임을 만들고 있습니다.사용자 정의 UIView가있는 UITouch가 작동하지 않습니다.
UIImageView
과 약간의 값을 사용하여 사용자 지정 UIView, UIPuzzle을 만들었습니다. 그때 나는 UIPuzzle
(UIPuzzle tab[16];
)의 테이블을 생성하는 UIPuzzleView
라는 새로운 클래스
나는 기본보기에 추가하고 (내가 그들 모두를 애니메이션 시도) 잘 작동을 만들었습니다. 그런 다음 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
을 사용하여 UIPuzzle
을 (를) 클릭했는지 확인하고 싶습니다. 여기
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch* touch = [touches anyObject];
int i = [self getTouchedView:[touch view]]; // this function returns me what UIPuzzle was clicked
if(i != NAN){
NSLog(@"%i", i);
}
}
-(int) getTouchedView:(UIView*)touch{
for(int i = 0 ; i < 4*4 ; i ++)
if(touch == gread[i])
return i;
return NAN;
}
보기
-(void)initGread{
int value = 0;
for(int i = 0 ; i < 4 ; i ++){
for(int j = 0 ; j < 4 ; j ++, value ++){
// setting size and pozition of single UIPuzzle
gread[value] = [[UIPuzzle alloc] initWithFrame:CGRectMake(j*70 + 70, i*70 + 70, 120, 120)];
// setting picture and value to UIPuzzle
[gread[value] setValue:value picture:[UIImage imageNamed:@"549823.jpg"]];
// adding UIPuzzle to View
[self addSubview:gread[value]];
}
}
}
이 작동합니다에 UIPuzzle
을 추가 기능을하지만, 그렇지 않습니다. 임의의 숫자를 반환하지만, 단지 gread[0]
, gread[1]
, gread[4]
, gread[5]
에 있습니다.
내가 클릭 한 것을 탐욕 얻을 getTouchedView을 사용 아래에 사용할 수 있습니다. 그러나 tnx는 그것을 사용하려고 노력할 것입니다. – poppytop