UIControl 详细解释

本文详细解析了UIControl的继承结构及其重要方法,包括如何自定义按钮ZSJButton,实现触摸事件的跟踪,如开始跟踪、持续跟踪和结束跟踪,并介绍了UIEvent的类型与子类型,展示了在不同事件阶段可以执行的操作和条件判断。
摘要由CSDN通过智能技术生成

第一 :UIControl 的继承。

UIControl 是继承与 UIView的。而 UIView继承与UIResponder的。然后 UIResponder 继承与 NSObject的。图形解释如下:




 第二:UIcontrol 的方法详细解释。

 一,创建一个继承与 UIcontrol 的类。

//  ZSJButton.h

//  基础(一)

//  Created by 周双建 on 16/4/5.

//  Copyright © 2016 周双建. All rights reserved.

#import <UIKit/UIKit.h>

@interface ZSJButton : UIControl{

    @public

    //标题

    UILabel * ZSJButtonTitle;

    //图片

    UIImageView * ZSJButtonImageView;

}

@end


二,该类的实现。

//  ZSJButton.m

//  基础(一)

//  Created by 周双建 on 16/4/5.

//  Copyright © 2016 周双建. All rights reserved.

#import "ZSJButton.h"

@implementation ZSJButton

-(instancetype)initWithFrame:(CGRect)frame{

    if (self == [super initWithFrame:frame]) {

        self.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:1.0f];

        self.layer.borderWidth = 0.5f;

        self.layer.borderColor = [[UIColor lightGrayColor] CGColor];

        self->ZSJButtonTitle = [[UILabel alloc]initWithFrame:CGRectMake(4.0f, 4.0f, frame.size.width-8.0f, frame.size.height - 8.0f)];

        self->ZSJButtonTitle.text = @"ZSJButton";

        self->ZSJButtonTitle.textColor = [[UIColor blackColor] colorWithAlphaComponent:1.0f];

        self->ZSJButtonTitle.font = [UIFont systemFontOfSize:20.0f];

        self->ZSJButtonTitle.textAlignment = NSTextAlignmentCenter;

        [self addSubview:self->ZSJButtonTitle];

    }

    return self;

}

// 这是开始启用跟踪事件

-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{

    if (touch.timestamp == 2.0f) {

        // 设置点击多长时间,才触发事件

    }

    if (touch.tapCount == 3) {

        // 设置点击的次数,连续点击

    }

    return [super beginTrackingWithTouch:touch withEvent:event];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值