0

問題があります。私は持っUIImageViewていUIButtonます。

ここに画像の説明を入力

UIButton矢印のように移動するときUIImageViewは、ボタンのフレームを変更する必要があります。UIImageViewそして、上にドラッグするときに回転する必要がありUIButtonます。

UIButton に Gesture を追加する必要があると思います。UIImageViewしかし、ドラッグしたときに新しいフレームを計算するにはどうすればよいUIButtonですか?

ありがとうございました

4

1 に答える 1

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特定の量を下回っているかどうかを確認してから、画像を回転させるメソッドを呼び出すことができます

于 2013-10-16T12:43:04.653 に答える