2013-10-16 33 views
0

我有问题。我有UIImageViewUIButtonUIView拖动UIButton时改变框架

enter image description here

当我移动UIButton如箭头所示,我需要改变按钮的帧UIImageView。当我拖动UIButton到顶部时,我需要旋转UIImageView

我想我需要在UIButton中添加手势。但我怎么能计算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是否低于一定数量,然后调用方法旋转图像