zoukankan      html  css  js  c++  java
  • UITouch 点击事件

    #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

     

  • 相关阅读:
    一个SQL语句实现的统计功能
    VS2005中的全角BUG(C#代码)[转]
    Observer Pattern(观察者模式)及其在C#中的实现
    我觉得VS2003中最差的地方
    上班了,有点困:(
    GPRS
    今天是郁闷的一天
    今天上午给公司老总演示了SharePoint项目的产品雏形
    介绍一下SharePoint
    SharePoint Service里面的东东真让人头疼
  • 原文地址:https://www.cnblogs.com/jx451578429/p/4755981.html
Copyright © 2011-2022 走看看