如何给scrollview上添加的子控件UIView上添加手势

    xiaoxiao2026-09-10  6

    如果不做特殊处理,在scrollView上添加子控件UIView添加手势,如果是拖拽,轻扫手势,会发现,不起作用个,而是scrollView处理了事件,会产生scrollerview拖动事件,这不是我们需要的效果,如何处理呢,自定义一个继承至uiscrollview的控件, 设置两个属性,self.delaysContentTouches = NO; self.canCancelContentTouches = YES; 并且: - (BOOL)touchesShouldCancelInContentView:(UIView *)view { return NO; }

    // // XBScrollView.h // 集速配 // // Created by aimee on 16/8/12. // Copyright © 2016年 LiangZhongXing. All rights reserved. // scrollView上面添加一个view做为子空间,view上面添加拖拽或清扫手势,让view手势有效 #import <UIKit/UIKit.h> @interface XBScrollView : UIScrollView @end #import "XBScrollView.h" @implementation XBScrollView /* scrollView上面添加一个view做为子空间,view上面添加拖拽或清扫手势,让view手势有效, 需要如下设置 */ - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.delaysContentTouches = NO; self.canCancelContentTouches = YES; } return self; } - (BOOL)touchesShouldCancelInContentView:(UIView *)view { return NO; } @end
    转载请注明原文地址: https://ju.6miu.com/read-1311920.html
    最新回复(0)