• 自定义target


    HomeViewController.m

    #import "HomeViewController.h"

    #import "TouchViewPro.h"

    @interface HomeViewController (){

        TouchViewPro *touchViewPro;

    }

    @end

    @implementation HomeViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        touchViewPro = [[TouchViewPro alloc] initWithFrame:CGRectMake(65, 65, 100, 100)];

        touchViewPro.backgroundColor = [UIColor blackColor];

        [self.view addSubview:touchViewPro];

        [touchViewPro addTarget:self action:@selector(change)];

        [touchViewPro release];

    }

    - (void)change {

        touchViewPro.frame = CGRectMake(arc4random() % (325 - 50 + 1) + 50, arc4random() % (325 - 50 + 1) + 50, arc4random() % 51, arc4random() % 70);

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

     -----------------------------------------------<TouchViewPro.h>-----------------------------------

    #import <UIKit/UIKit.h>

    @interface TouchViewPro : UIView

    - (void)addTarget:(id)target action:(SEL)action;

    @end

     --------------------------------------------------<TouchViewPro.m>-------------------------------------------------

    #import "TouchViewPro.h"

    @interface TouchViewPro(){

        id _target;

        SEL _action;

    }

    @end

    @implementation TouchViewPro

    - (void)addTarget:(id)target action:(SEL)action {

        _action = action;

        _target = target;

    }

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

        [_target performSelector:_action withObject:self];

        

    //    self.frame = CGRectMake(arc4random() % (325 - 50 + 1) + 50, arc4random() % (325 - 50 + 1) + 50, arc4random() % 51, arc4random() % 70);

    }

    @end

  • 相关阅读:
    c++中memset()函数的用法
    not exits用法讲解(以查询选修全部课程的学生为例)
    数据库中冲突可串行化的判断
    如何快速的判断一个数是否是完全平方数
    杭电oj2089c++
    3月7日学习日志
    3月5日 学习日志
    免编译二进制安装mysql5.7
    base64转换为图片以及图片转换为base64码
    Eclipse编辑JS响应慢,复制粘贴卡顿的解决方案
  • 原文地址:https://www.cnblogs.com/hsxblog/p/4926234.html
Copyright © 2020-2023  润新知