1

私のアプリでは、UiLabel を作成しました。スライドアウトメニューのように、タッチジェスチャに応じてラベルを右に移動する必要があります。私を助けてください。

4

3 に答える 3

1

UITapGestureRecognizer を使用できます。

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];

[label addGestureRecognizer:singleTap];

次に、メソッドで UIViewAnimation を使用します。

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {


     CGRect frame = label.frame;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

     frame.origin.x += 100; // slide right
    label.frame = frame;

    [UIView commitAnimations];
}
于 2013-01-21T07:49:50.883 に答える
0

CGPointMake関数を使用して位置を供給します

label.position = CGPointMake (newX, newY);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.duration = <duration>;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
animation.fromValue = CGPointMake (oldX, oldY);
animation.toValue = CGPointMake (newX, newY);
[label addAnimation:animation forKey:@"position"];
于 2013-01-21T07:52:58.863 に答える
0

UILabel アウトレット名が testing であるとします。

// set up geture as follows in view did load
UISwipeGestureRecognizer* swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(labelDidSwiped:)];
[swipeGesture setDirection: UISwipeGestureRecognizerDirectionLeft];
[testing addGestureRecognizer:swipeGesture];

swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(labelDidSwiped:)];
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionRight];

[testing addGestureRecognizer:swipeGesture];

-(void)labelDidSwiped:(UISwipeGestureRecognizer*)gesture
{
switch (gesture.direction) {
    case UISwipeGestureRecognizerDirectionLeft:
        // you can change the frame of label in here depending on your requirement
        DLog(@"left swipe");
        break;
    case UISwipeGestureRecognizerDirectionRight:
// you can change the frame of label in here depending on your requirement
        break;
    default:
        break;
 }
}
于 2013-01-21T07:51:06.210 に答える