我正在尝试添加UISwipeGestureRecognition
到自定义视图。我想做与 IOS 通知相同的操作,但以另一种方式。我以前用 做过tapGesture
,但是当我用滑动添加尝试时,它不起作用。
我正在使用此代码。这是一个隐藏的 tableView,当我swipeUp
用一根手指做 a 时会显示它。
我现在的问题是视图上升但在主视图后面。
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *headerLabel = [[UILabel alloc]init];
headerLabel.tag = section;
headerLabel.userInteractionEnabled = YES;
headerLabel.backgroundColor = [UIColor salmonUser];
headerLabel.text = [NSString stringWithFormat:@"Interesteds"];
headerLabel.frame = CGRectMake(100, 0, 120,tableView.tableHeaderView.frame.size.height);
[headerLabel setTextAlignment:NSTextAlignmentCenter];
UISwipeGestureRecognizer *upRecognizer= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[upRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
UISwipeGestureRecognizer *downRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[downRecognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
[headerLabel addGestureRecognizer:upRecognizer];
[headerLabel addGestureRecognizer:downRecognizer];
return headerLabel;
//return nil;
}
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
{
NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
BOOL switchUpDown = [d boolForKey:@"switchUpDown"];
UISwipeGestureRecognizerDirection up = switchUpDown ? UISwipeGestureRecognizerDirectionUp : UISwipeGestureRecognizerDirectionDown;
UISwipeGestureRecognizerDirection down = switchUpDown ? UISwipeGestureRecognizerDirectionDown : UISwipeGestureRecognizerDirectionUp;
if (recognizer.direction == up){
[UIView animateWithDuration:0.3
delay:0.3
options: UIViewAnimationCurveEaseOut
animations:^{
CGRect rect = self.view.frame;
rect.origin.y = self.view.frame.size.height-(self.view.frame.size.height/2);
self.usersView.frame = rect;
mostrada =true;
}
completion:^(BOOL finished){}];
} else if(recognizer.direction == down){
[UIView animateWithDuration:0.3
delay:0.3
options: UIViewAnimationCurveEaseOut
animations:^{
CGRect rect = self.view.frame;
rect.origin.y = self.view.frame.size.height-(self.view.frame.size.height/11);
self.usersView.frame = rect;
mostrada=false;
}
completion:^(BOOL finished){
}];
}
}