2011-03-04 2 views
0

내 스크롤러 내에있는 이미지를 스크롤러에서 이미지 뷰로 끌 수 있는지 어떻게 확인할 수 있습니까?해당 위치를 손상시키지 않고 스크롤 뷰에서 이미지를 드래그

또한 '흔들기'를 구현하고 싶습니다. 사용자가 스크롤러 내에서 이미지를 탭하면 이미지가 흔들리고 사용자의 터치가 다른보기로 이어집니다. 하위 뷰를 만드는 것으로 시작했지만 이미지가 정상보기로 표시 될 때 위치가 바뀌지 않고 뷰의 맨 위에 표시됩니다.

  • 이미지 흔들
  • 이미지가 다른보기로 이동 :

    어떻게 내가 이미지를 터치하면 확인 할 수 있습니다.

  • 이미지가 사용하는 대신에

(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:self.view]; 

    image1.userInteractionEnabled = YES; 
    [self.view addSubview:image1]; 

    if([touch view] == image1){ 

     image1.center = location; 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:0.14]; 
     [UIView setAnimationRepeatAutoreverses:YES]; 
     [UIView setAnimationRepeatCount:1000000]; 

     image1.transform = CGAffineTransformMakeRotation(69); 
     image1.transform = CGAffineTransformMakeRotation(-69); 

     [UIView commitAnimations]; 
     image1.center = CGPointMake(30,870);   
    } 

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *) event { 

    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:self.view]; 

    if([touch view] == image1){ 
     image1.userInteractionEnabled = YES; 
     [self.view addSubview:image1]; 
     image1.center = location; 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:0.14]; 
     [UIView setAnimationRepeatAutoreverses:YES]; 
     [UIView setAnimationRepeatCount:1000000]; 

     image1.transform = CGAffineTransformMakeRotation(69); 
     image1.transform = CGAffineTransformMakeRotation(-69); 

     [UIView commitAnimations]; 
    } 

답변

0

은 내가 gestureRecognizers 사용 '기능 접촉'내 터치 위치에 따라. 특정 이미지 (LongpressRecognizer의 TapRecognizer)에 인식기를 추가 할 수 있습니다. 사용자가 이미지를 누르면 앱이 터치를 인식합니다. 이후에는 "[self.view addSubview : yourImage]; 함수를 사용하여 이미지를 기본보기 상단의 하위보기에 넣을 수 있습니다.

다음은 위임 기능을

-(void)longPressed:(UILongPressGestureRecognizer *)sender { 

    CGPoint location = [sender locationInView:self.view]; 

    [self.view addSubview:yourimage]; 
    yourimage.center = location; 
    //perform a transform (wiggle or scale) 
    if([(UILongPressGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { 
     yourimage.transform = CGAffineTransformMakeScale(1.0, 1.0); 
     //stop the transform 

    } 
} 

희망 사용이 Elppa을 당신을하는 데 도움이 Afterwords 당신이 당신의 viewDidLoad, viewDidAppear 또는 viewWillappear 방법

UILongPressGestureRecognizer *longPress = 
    [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)]; 
    longPress.minimumPressDuration = 0.7; 
    [yourimage addGestureRecognizer:longPress1]; 

에 gesturerecognizer을 정의하라 SNIPPIT

우선이다

관련 문제