Я не могу установить успешный UISwipeGestureRecognizer на свой пользовательский вид. Я успешно проверил на главном self.view
, но я не могу заставить его работать над моим обычаем.iOS, UISwipeGestureRecognizer on Custom UIView - не работает
Parent.m
@property (strong, nonatomic) UISummaryChartView *chartView;
...
- (void)viewDidLoad {
[super viewDidLoad];
self.chartView = [[UISummaryChartView alloc] initWithWidth:self.view.frame.size.width andHeight:self.view.frame.size.height withView:self.view];
[self.chartView openBox];
UISwipeGestureRecognizer *swipeGest = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDetected:)];
[swipeGest setDirection:(UISwipeGestureRecognizerDirectionUp)];
[self.view addGestureRecognizer:swipeGest];
}
-(void)swipeDetected: (UISwipeGestureRecognizer *) sender{
NSLog(@"swiped..");
if(self.chartView.frame.size.height > 50){
//chart view is open
NSLog(@"closing");
[self.chartView closeBox];
}
}
UISummaryChartView.h
UISummaryChartView : UIView
-(id) initWithWidth:(CGFloat)inWidth andHeight:(CGFloat)inHeight withView: (UIView*) theView{
self = [super init];
self.mainView = theView;
//super view bounds
self.viewWidth = inWidth;
self.viewHeight = inHeight;
CGFloat startx = 2;
CGFloat starty = 0;
self.width = self.viewWidth - 10;
self.height = (self.viewHeight/100) * 50;
self.view1Frame = CGRectMake(startx, starty, self.width, self.height);
return self;
}
-(void) openBox{
CGRect startFrame = CGRectMake(0, 10, self.mainView.frame.size.width, 1);
self.view1 = [[UIView alloc] initWithFrame:startFrame];
[self.mainView addSubview:self.view1];
[UIView animateWithDuration:0.5 animations:^(void){
[self.view1 setBackgroundColor:[UIColor colorWithRed:(float)126/255.0 green:(float)35/255.0 blue:(float)32/255.0 alpha:1]];
self.view1.frame = self.view1Frame;
} completion:^(BOOL finished){
}];
}
вы хотите закрыть свой пользовательский вид с подобным жестом? – Matt
Да, проведите по экрану, чтобы закрыть его. –