Iphone ui拖动ui按钮时查看更改帧
我有问题。我有Iphone ui拖动ui按钮时查看更改帧,iphone,ios,uiimageview,rotation,frame,Iphone,Ios,Uiimageview,Rotation,Frame,我有问题。我有ui图像视图和ui按钮 当我移动ui按钮时,如箭头所示,我需要更改按钮的帧ui图像视图。当我将ui按钮拖动到顶部时,我需要旋转ui图像视图 我想我需要在UIButton中添加手势。但是,当我拖动ui按钮时,如何计算UIImageView的新帧呢 多谢各位 @synthesize resizableImageView; @synthesize resizeButton; - (void)viewDidLoad { [super viewDidLoad]; // Do
ui图像视图
和ui按钮
当我移动ui按钮时,如箭头所示,我需要更改按钮的帧ui图像视图
。当我将ui按钮
拖动到顶部时,我需要旋转ui图像视图
我想我需要在UIButton中添加手势。但是,当我拖动ui按钮时,如何计算UIImageView
的新帧呢
多谢各位
@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];
}
这(几乎)成功地实现了您可调整大小的行为。旋转图像,也许您可以检查[[signature valueForKey:@“\u lastScreenLocation”]CGPointValue].y
是否低于某个值,然后调用方法旋转图像