我有问题。我有UIImageView
UIButton
。
当我按箭头指示移动UIButton
时,我需要更改按钮的第UIImageView
帧。当我将UIImageView
拖到顶部时,我需要轮播UIButton
。
我想我需要在UIButton中添加Gesture。但是,当我拖动UIImageView
时,我如何计算UIButton
的新框架?
谢谢
答案 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
是否低于某个数量,然后调用方法旋转图像