Ios UI视图动画向上或向下滑动
我在获取上下滑动的动画时遇到问题。 这是到目前为止我的代码。在屏幕上滑动时,它只会设置动画,但对象不起作用Ios UI视图动画向上或向下滑动,ios,objective-c,iphone,Ios,Objective C,Iphone,我在获取上下滑动的动画时遇到问题。 这是到目前为止我的代码。在屏幕上滑动时,它只会设置动画,但对象不起作用 ViewController.m // notificationView // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; Notif
ViewController.m
// notificationView
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NotificationView *notifications= [[NotificationView 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 {
UISwipeGestureRecognizer *swipe = (UISwipeGestureRecognizer *) sender;}
-(void) swipeDown:(id) sender { }
@end
试试这个,它的工作很完美
- (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);
}];
}
我想你和代表失踪了。在标题中设置UIgestureRecognitizerDelegate。如果您对我的答案感到满意,请不要放弃正确标记我的答案。