UIView在拖动UIButton时更改框架

时间:2013-10-16 04:40:08

标签: iphone ios uiimageview rotation frame

我有问题。我有UIImageView UIButton

enter image description here

当我按箭头指示移动UIButton时,我需要更改按钮的第UIImageView帧。当我将UIImageView拖到顶部时,我需要轮播UIButton

我想我需要在UIButton中添加Gesture。但是,当我拖动UIImageView时,我如何计算UIButton的新框架?

谢谢

1 个答案:

答案 0 :(得分: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是否低于某个数量,然后调用方法旋转图像