UI视图动画向上或向下滑动

时间:2016-10-07 23:46:30

标签: ios objective-c iphone

我无法通过向上或向下滑动来制作此动画。 到目前为止,这是我的代码。它只是动画,但在屏幕上滑动时对象不起作用。

index.html

1 个答案:

答案 0 :(得分:1)

尝试这是完美的工作。

  - (void)viewDidLoad {
    [super viewDidLoad];

    notifications = [[UIView alloc] initWithFrame:CGRectMake(200,200,200,200)];
    notifications.backgroundColor =[ UIColor blueColor];
    [self.view addSubview:notifications];

    UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:
                                         @selector(swipeUp:)];
    [notifications addGestureRecognizer:swipeUp];

    swipeUp.direction=UISwipeGestureRecognizerDirectionUp;

    UISwipeGestureRecognizer *swipeDown=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:
                                         @selector(swipeDown:)];

    swipeDown.direction=UISwipeGestureRecognizerDirectionDown;
    [notifications addGestureRecognizer:swipeDown];

    [UIView animateWithDuration:0.5 animations:^{
        notifications.center=CGPointMake(150,150);
    }];
}

-(void) swipeUp:(id) sender {

   [self animationOfObject:150 yVlaue:150];
}

-(void) swipeDown:(id) sender {

  [self animationOfObject:150 yVlaue:300];
}

-(void)animationOfObject:(float)xValue yVlaue:(float)yValue
{
    [UIView animateWithDuration:0.5 animations:^{
        notifications.center=CGPointMake(xValue,yValue);
    }];
}