#ios #objective-c #iphone
#iOS #objective-c #iPhone
Вопрос:
У меня возникли проблемы с получением этой анимации для прокрутки вверх или вниз для работы. Вот мой код на данный момент. Он только анимирует, но объект не работает при пролистывании по экрану.
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
Комментарии:
1. Я думаю, вам не хватает делегата. установите UIGestureRecognizerDelegate в заголовке.
Ответ №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);
}];
}
Комментарии:
1. если вы удовлетворены моим ответом, не забудьте отметить мой ответ.