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