2013-10-16 4 views
0

문제가 있습니다. 나는 UIImageViewUIButton을 가지고 있습니다. UIButton을 드래그 할 때 UIView 변경 프레임

enter image description here

화살표로 나타낸 바와 같이, I가 UIButton 이동

는 I 버튼 프레임 UIImageView을 변경할 필요가있다. UIButton을 맨 위로 드래그하면 UIImageView을 회전해야합니다.

UButton에 제스처를 추가해야한다고 생각합니다. 그렇다면 UIImageView에 대한 새 프레임을 계산할 때 UIButton을 드래그하면 어떻게 될까요?

답변

1
@synthesize resizableImageView; 
@synthesize resizeButton; 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    [resizeButton addTarget:self action:@selector(startDraggableCorner) forControlEvents:UIControlEventTouchDown]; 
    [resizeButton addTarget:self action:@selector(stopDraggableCorner) forControlEvents:UIControlEventTouchUpInside]; 
} 
-(void)startDraggableCorner 
{ 
    gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(wasDragged:)]; 
    [[self view] addGestureRecognizer:gestureRecognizer]; 
} 
-(void)wasDragged:(UIPanGestureRecognizer*)gesture 
{ 
    CGRect imageFrame = [resizableImageView frame]; 
    imageFrame.size.height = [[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].y - imageFrame.origin.y; 
    imageFrame.size.width = [[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].x - imageFrame.origin.x; 
    [resizableImageView setFrame: imageFrame]; 
    CGRect buttonFrame = [resizeButton frame]; 
    buttonFrame.origin.x = [[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].x; 
    buttonFrame.origin.y = [[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].y; 
    [resizeButton setFrame:buttonFrame]; 

} 
-(void)stopDraggableCorner 
{ 
    [[self view] removeGestureRecognizer:gestureRecognizer]; 
} 

이 (거의) 당신의 크기 조정 동작에 성공 해 주셔서 감사합니다. 이미지를 회전하면 [[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].y이 일정량 미만인지 확인한 다음 이미지 회전 방법을 호출 할 수 있습니다.

관련 문제