新建自定義ScrollView ?加入代碼
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer {
? ? if([selfpanBack:gestureRecognizer]) {
? ? ? ? returnYES;
? ? }
? ? return NO;
}
//location_X可自己定義,其代表的是滑動(dòng)返回距左邊的有效長(zhǎng)度
- (BOOL)panBack:(UIGestureRecognizer*)gestureRecognizer {
? ? //是滑動(dòng)返回距左邊的有效長(zhǎng)度
? ? intlocation_X =40;
? ? if(gestureRecognizer ==self.panGestureRecognizer) {
? ? ? ? UIPanGestureRecognizer *pan = (UIPanGestureRecognizer *)gestureRecognizer;
? ? ? ? CGPointpoint = [pantranslationInView:self];
? ? ? ? UIGestureRecognizerStatestate = gestureRecognizer.state;
? ? ? ? if (UIGestureRecognizerStateBegan == state ||UIGestureRecognizerStatePossible == state) {
? ? ? ? ? ? CGPointlocation = [gestureRecognizerlocationInView:self];
? ? ? ? ? ? //這是允許每張圖片都可實(shí)現(xiàn)滑動(dòng)返回
? ? ? ? ? ? //? ? ? ? ? ? int temp1 = location.x;
? ? ? ? ? ? //? ? ? ? ? ? int temp2 = KScreenW;
? ? ? ? ? ? //? ? ? ? ? ? NSInteger X = temp1 % temp2;
? ? ? ? ? ? //? ? ? ? ? ? if (point.x >0 && X < location_X) {
? ? ? ? ? ? //? ? ? ? ? ? ? ? return YES;
? ? ? ? ? ? //? ? ? ? ? ? }
? ? ? ? ? ? //下面的是只允許在第一張時(shí)滑動(dòng)返回生效
? ? ? ? ? ? if(point.x>0&& location.x< location_X &&self.contentOffset.x<=0) {
? ? ? ? ? ? ? ? returnYES;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? return NO;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
? ? if([selfpanBack:gestureRecognizer]) {
? ? ? ? returnNO;
? ? }
? ? return YES;
}