zoukankan      html  css  js  c++  java
  • 自定义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

  • 相关阅读:
    Linux系统挂载点与分区的关系(转载)
    读书笔记深入linux内核架构Chapter 2 part2
    读书笔记深入linux内核架构Chapter 2 part1
    读书笔记深入linux内核架构Chapter9
    读书笔记深入linux内核架构Chapter8part2
    鞋匠的烦恼
    和最大的连续子数组
    wxLog 的使用
    suffix trie
    trie
  • 原文地址:https://www.cnblogs.com/hsxblog/p/4926234.html
Copyright © 2011-2022 走看看