無(wú)意間看到文明大神的 ScreenShotBack的 全屏返回腥沽,截圖手勢(shì)返回谅将,景深效果,類(lèi)似斗魚(yú)重慢、天天快報(bào)饥臂、騰訊新聞等APP的手勢(shì)返回。
感覺(jué)實(shí)現(xiàn)的效果非常好似踱, 本人非常喜歡今日頭條也喜歡他的全屏返回手勢(shì)的效果
先來(lái)體驗(yàn)一下文明大神的效果
文明效果.gif
效果非常好, 但是有一個(gè)待完善的東西是: 我們?cè)谌练祷卦斍轫?yè)面的時(shí)候隅熙,發(fā)現(xiàn)tableView的數(shù)據(jù)可以上下滑動(dòng), 這是我們不愿意看到的
自己針對(duì)這種情況做了修改
BaseNavigationController.m
中的
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
NSLog(@"shouldRecognizeSimultaneouslyWithGestureRecognizer---%@", otherGestureRecognizer);
if ([otherGestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")] || [otherGestureRecognizer isKindOfClass:NSClassFromString(@"UIPanGestureRecognizer")]|| [otherGestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPagingSwipeGestureRecognizer")]){
//沖突要有兩個(gè),二者不可兼得
UIView *aView = otherGestureRecognizer.view;
if ([aView isKindOfClass:[UIScrollView class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
UIScrollView *sv = (UIScrollView *)aView;
CGFloat svWidth = sv.contentSize.width;
NSInteger subViewsNum = svWidth/[UIScreen mainScreen].bounds.size.width;
UIPanGestureRecognizer *panGest = (UIPanGestureRecognizer *)otherGestureRecognizer;
CGPoint translation = [panGest translationInView:self.view];
//設(shè)置左滑和右滑的情況
// 右滑的情況
if (translation.x > 0){
// 如果是scrollView多視圖 類(lèi)似附近 廣場(chǎng) 推薦的滾動(dòng)
if((sv.contentOffset.x==0) && (subViewsNum > 1) ){
return YES;
}
}else{
// tableView的左滑
if ((sv.contentOffset.x==0) && (subViewsNum == 1)){
return YES;
}
}
}
}
return NO;
}
轉(zhuǎn)機(jī)
聯(lián)系到作者文明大神, 給出了較好的解決方案核芽。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
NSLog(@"shouldRecognizeSimultaneouslyWithGestureRecognizer---%@", otherGestureRecognizer);
if ([otherGestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")] || [otherGestureRecognizer isKindOfClass:NSClassFromString(@"UIPanGestureRecognizer")]|| [otherGestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPagingSwipeGestureRecognizer")]){
//沖突要有兩個(gè)囚戚,二者不可兼得
UIView *aView = otherGestureRecognizer.view;
if ([aView isKindOfClass:[UIScrollView class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
UIScrollView *sv = (UIScrollView *)aView;
//設(shè)置左滑和右滑的情況
// 右滑的情況
// 如果是scrollView多視圖 類(lèi)似附近 廣場(chǎng) 推薦的滾動(dòng)
if([sv isKindOfClass:[UITableView class]]){
return NO;
}
// 如果是scrollView多視圖 類(lèi)似附近 廣場(chǎng) 推薦的滾動(dòng)
if(sv.contentOffset.x==0){
return YES;
}
}
}
return NO;
}
感覺(jué)現(xiàn)在我們解決方法 并不好 所以還望各位大神可以給出指導(dǎo)意見(jiàn)! 小弟不勝感激轧简! 修改后的代碼在我的gitHub上 SmallTwoInn/ScreenShotBack
晚上吧自己修改這個(gè)問(wèn)題的心理路程好好記錄下驰坊!
Gesture Recognizers與觸摸事件分發(fā)