博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UITouch 点击事件
阅读量:6979 次
发布时间:2019-06-27

本文共 3424 字,大约阅读时间需要 11 分钟。

#import "AppDelegate.h"

#import "ViewController.h"

@interface AppDelegate ()

 

@end

 

@implementation AppDelegate

 

- (void)dealloc

{

    [_window release];

    [super dealloc];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    

    ViewController *rootVC = [[ViewController alloc]init];

    self.window.rootViewController = rootVC;

    [rootVC release];

    

    [self.window makeKeyAndVisible];

    return YES;

}

 

 

 

 

#import "ViewController.h"

#import "TView.h"

@interface ViewController ()

 

@end

 

@implementation ViewController

 

 

 

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    TView *view1 = [[TView alloc]initWithTarget:self Action:@selector(changeCount:)];

    view1.frame = CGRectMake(40, 100, 100, 100);

    view1.backgroundColor = [UIColor colorWithHue:arc4random() % 256 / 255.0 saturation:arc4random() % 256 / 250.0 brightness:arc4random() % 256 /250.0 alpha:1.0];

    [self.view addSubview:view1];

    [view1 release];

    

    TView *view2 = [[TView alloc]initWithTarget:self Action:@selector(changeFrame:)];

    view2.frame = CGRectMake(200, 100, 100, 100);

    view2.backgroundColor = [UIColor colorWithHue:arc4random() % 256 / 255.0 saturation:arc4random() % 256 / 250.0 brightness:arc4random() % 256 /250.0 alpha:1.0];

    [self.view addSubview:view2];

    [view2 release];

    

    TView *view3 = [[TView alloc]initWithTarget:self Action:@selector(changeSize:)];

    view3.frame = CGRectMake(40, 300, 100, 100);

    view3.backgroundColor = [UIColor colorWithHue:arc4random() % 256 / 255.0 saturation:arc4random() % 256 / 250.0 brightness:arc4random() % 256 /250.0 alpha:1.0];

    [self.view addSubview:view3];

    [view3 release];

    

}

 

- (void)changeCount:(UIView *)view

{

    view.backgroundColor = [UIColor colorWithHue:arc4random() % 256 / 255.0 saturation:arc4random() % 256 / 250.0 brightness:arc4random() % 256 /250.0 alpha:1.0];

}

 

- (void)changeFrame:(UIView *)view

{

    view.center = CGPointMake(arc4random() % 320, arc4random() % 480);

 

}

 

- (void)changeSize:(UIView *)view

{

    

    view.frame = CGRectMake(40, 300, arc4random() % 320 + 20, arc4random() % 480 + 20);

 

}

 

 

 

 

#import <UIKit/UIKit.h>

 

@interface TView : UIView

{

    id _target;

    SEL _action;

}

 

- (id)initWithTarget:(id)target Action:(SEL)action;

 

@end

 

 

 

 

#import "TView.h"

 

@implementation TView

 

- (id)initWithTarget:(id)target Action:(SEL)action

{

    self = [super init];

    if (self) {

        _target = target;

        _action = action;

    }

    return self;

}

 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    [_target performSelector:_action withObject:self];

}

 

 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    

    UITouch *touch = [touches anyObject];

    CGPoint point = [touch locationInView:self.superview];

    CGPoint point1 = [touch previousLocationInView:self.superview];

    CGPoint center = self.center;

    CGPoint point2 = CGPointMake(point.x - point1.x, point.y - point1.y);

    self.center = CGPointMake(center.x + point2.x, center.y + point2.y);

 

   

}

 

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

{

    

   

}

 

 

 

 

 

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/

 

@end

 

转载于:https://www.cnblogs.com/jx451578429/p/4755981.html

你可能感兴趣的文章
shareinstall可以解决地推统计这个难题
查看>>
Mac Mysql Access denied for user 'root'@'localhost
查看>>
Python学习三级菜单
查看>>
访问控制
查看>>
JPA中EntityListeners注解的使用
查看>>
苹果手机如何恢复通讯录联系人呢?怎样恢复
查看>>
SQL基础教程
查看>>
如何编辑修改PDF,PDF怎么删除页眉页脚
查看>>
科学热点:国内首家无人书店亮相,315曝光机器人打骚扰电话
查看>>
600万死难者记忆由AI守护!以色列博物馆用AI索引数字资产
查看>>
iOS开发之网络编程--小文件下载
查看>>
CSS强制文本在一行内显示若有多余字符则使用省略号表示
查看>>
蛋花花谈Web前端工程师掌握这些技能更加顺利工作
查看>>
AJPFX的反射学习笔记
查看>>
Android学习--08-ListView
查看>>
polymer中的notify和reflectToAttribute
查看>>
Java排序二叉树
查看>>
从其他机构转投乾颐堂的同学pass感言
查看>>
卷积神经网络CNN原理以及TensorFlow实现
查看>>
教程:怎样处理资源管理器崩溃退出的问题
查看>>