美文网首页
UIButton与手势混搭的结果【入门】

UIButton与手势混搭的结果【入门】

作者: 码农二哥 | 来源:发表于2020-03-12 08:30 被阅读0次

只有UIButton

@interface WUIButton : UIButton
@end
@implementation WUIButton

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    NSLog(@"xiaowei.li:%s", __FUNCTION__);
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
    NSLog(@"xiaowei.li:%s", __FUNCTION__);
}

-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesCancelled:touches withEvent:event];
    NSLog(@"xiaowei.li:%s", __FUNCTION__);
}

@end

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.wButton = [[WUIButton alloc] initWithFrame:CGRectMake(100, 100, 150, 44)];
    self.wButton.backgroundColor = UIColor.purpleColor;
    [self.wButton setTitle:@"test-normal" forState:UIControlStateNormal];
    [self.wButton setTitle:@"test-highlighted" forState:UIControlStateHighlighted];
    [self.wButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.wButton];
}

- (void)buttonClicked
{
    NSLog(@"xiaowei.li:%s", __FUNCTION__);
}
  • 正常点击以下的输入如下:
xiaowei.li:-[WUIButton touchesBegan:withEvent:]
xiaowei.li:-[ViewController buttonClicked]
xiaowei.li:-[WUIButton touchesEnded:withEvent:]

UIButton+手势


  • WUIButton实现逻辑不变
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.wButton = [[WUIButton alloc] initWithFrame:CGRectMake(100, 100, 150, 44)];
    self.wButton.backgroundColor = UIColor.purpleColor;
    [self.wButton setTitle:@"test-normal" forState:UIControlStateNormal];
    [self.wButton setTitle:@"test-highlighted" forState:UIControlStateHighlighted];
    [self.wButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.wButton];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    [self.wButton addGestureRecognizer:tap];
}
- (void)buttonClicked
{
    NSLog(@"xiaowei.li:%s", __FUNCTION__);
}

- (void)tap
{
    NSLog(@"xiaowei.li:%s", __FUNCTION__);
}
  • 结果会怎样?
xiaowei.li:-[WUIButton touchesBegan:withEvent:]
xiaowei.li:-[ViewController tap]
xiaowei.li:-[WUIButton touchesCancelled:withEvent:]

如果换成pan手势呢?结果会怎样?

  • 普通点击效果(点击时不要移动):
xiaowei.li:-[WUIButton touchesBegan:withEvent:]
xiaowei.li:-[ViewController buttonClicked]
xiaowei.li:-[WUIButton touchesEnded:withEvent:]
  • 点击后稍微移动以下:
xiaowei.li:-[WUIButton touchesBegan:withEvent:]
xiaowei.li:-[ViewController panCallback]
xiaowei.li:-[WUIButton touchesCancelled:withEvent:]
xiaowei.li:-[ViewController panCallback]
xiaowei.li:-[ViewController panCallback]
...

相关文章

  • UIButton与手势混搭的结果【入门】

    只有UIButton 正常点击以下的输入如下: UIButton+手势 WUIButton实现逻辑不变 结果会怎样...

  • 鬼灭之刃三人组特写

    手里资源有限。。结果。。彩铅与马克笔的混搭。。。还拿个素描本画的。。马克混不了色。。。以后这本尽量都彩铅吧!

  • 每日一画~

    铅笔素描与水彩的混搭

  • 混搭的写法

    混搭的写法,就好比穿衣服混搭一样,可以是大和小混搭,可以是色彩的混搭,可以是风格的混搭,可以是深浅的混搭,可以是现...

  • iOS点击事件和手势冲突

    场景: 1.父视图添加了左划手势,触发返回方法 2.子视图添加了UIButton 出现的结果bug: 每次点击确认...

  • 混搭 与 不搭

    地上的井盖在路口喷汽 窗外的宝马在路边罚站 立交桥转几个弯又回头 迂回不舍的是爱与不爱 喝着红酒吃着汉中凉皮 烤串...

  • IOS 开发 问题记录

    1.view添加了手势,view上的UIButton的点击事件就会被手势拦截。 解决方案:在手势的代理里面做判断。...

  • 混搭?混搭

    混搭?混搭! 今天去拜访雷子。 雷子不在家,接待我的是雷子妈妈。 雷子的儿子每况愈下,最近考试只有20分了。 ”怎...

  • 事件传递和响应机制,持续更新

    第一响应者查找 视图点击 UITapgesture手势点击 UIControl,UIButton点击 mark

  • iOS开发:UIScrollView 与 UIButton 手势

    问题描述: 在UIScrollView中加入UIButton后,在button区域无法进行滑动操作,有时候我们可能...

网友评论

      本文标题:UIButton与手势混搭的结果【入门】

      本文链接:https://www.haomeiwen.com/subject/yayejhtx.html