>

UIScrollView 가있다  그것은 확대 UIImageView 가 즉, 다음을 구현합니다.

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imageView;
}

UIRotationGestureRecognizer 를 추가하려고합니다  이 imageView 에  그리고 나는 다음과 같이합니다 :

_rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
[self.imageView addGestureRecognizer:_rotationGestureRecognizer];
-(void)rotate:(id)sender
{
    UIRotationGestureRecognizer *rotationGestureRecognizer = [(UIRotationGestureRecognizer*)sender retain];
    if(rotationGestureRecognizer.state == UIGestureRecognizerStateEnded)
    {
        self.lastRotation = 0.0;
        return;
    }
    CGFloat rotation = 0.0 - (self.lastRotation - rotationGestureRecognizer.rotation);
    rotationGestureRecognizer.view.transform = CGAffineTransformRotate(rotationGestureRecognizer.view.transform, rotation);
    self.lastRotation = rotationGestureRecognizer.rotation;
    [rotationGestureRecognizer release];
}

그냥 궁금합니다. 심지어 이것을 할 수 있습니까? 그것은 UIScrollView 것 같다  내 UIImageView 에 접촉을 차단  아무 일도 일어나지 않기 때문입니다. 애플은 UIScrollView 에서 확대보기로 이것을하지 않는 것이 좋습니다 ?


  • 답변 # 1

    다음 코드가 작동합니다. imageView 대신 scrollView에 제스처를 추가하십시오.

    UIRotationGestureRecognizer* _rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
     [self.scrollView addGestureRecognizer:_rotationGestureRecognizer];
    
    

    Swift 5 버전 :

    let rotationGestureRecognizer = UIRotationGestureRecognizer(target: self, action: #selector(self.rotate(_:)))
    scrollView.addGestureRecognizer(rotationGestureRecognizer)
    
    

  • 답변 # 2

    -(void)rotate:(UIRotationGestureRecognizer *)sender
    {   
        [self bringSubviewToFront:[(UIRotationGestureRecognizer*)sender view]]; 
        if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) 
        {       
            lastRotation = 0.0;
            return;
        }
        CGFloat rotation = 0.0 - (lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);  
        CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
        CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation);   
        [[(UIRotationGestureRecognizer*)sender view] setTransform:newTransform];    
        lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
        lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
    }
    
    

  • 이전 emacs - zsh를 사용하는 쉘 모드의 이상한 문자
  • 다음 emacs - orgmodeorg/manual/Installationhtml에 대한 조직 소스 코드는 어디에서 찾을 수 있습니까?