UITouch & UIViewController

来源:互联网 发布:ce系统导航软件 编辑:程序博客网 时间:2024/05/21 23:37

//    UIViewController


- (void)loadView;//加载视图(只调用一次)

- (void)viewDidLoad;//加载视图(只调用一次)

- (void)viewWillAppear:(BOOL)animated;//视图加载之后被调用(只调用一次)

- (void)viewDidAppear:(BOOL)animated;//视图出现的时候调用

- (void)viewWillDisappear:(BOOL)animated;//视图将要消失的时候调用

- (void)viewDidDisappear:(BOOL)animated;//视图消失的时候调用

- (void)didReceiveMemoryWarning;//接受到内存警告的时候调用



//    UITouch

self.userInteractionEnabled = YES;//允许用户交互

//开始触摸时

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

{

//   

//    UITouch *touch = [touches anyObject]; //获取手指对象

//    _beginPoint = [touch locationInView:self]; //获取当前视图点击的坐标

////CGPoint point = [touch locationInView:self];//获取当前视图点击的坐标

//    NSLog(@"%f %f",_beginPoint.x , _beginPoint.y);//打印坐标观察结果

//    self.layer.shadowColor = [UIColor blackColor].CGColor;

//    self.layer.shadowOffset = CGSizeMake(3, 5);//设置阴影坐标

//    self.layer.shadowOpacity = 1;//阴影透明度

//   

    


//    struct CGPoint {      //CGPoint 的内容 (是一个结构体)

//        CGFloat x;

//        CGFloat y;

//    };

//    typedef struct CGPoint CGPoint;

    

    

}

//移动时

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

{

        

    UITouch *touch = [touches anyObject]; //获取手指对象

    CGPoint point = [touch locationInView:self.superview]; //获取当前父视图点击的坐标

    self.frame = CGRectMake(point.x - _beginPoint.x , point.y - _beginPoint.y,self.frame.size.widthself.frame.size.height);//获取点击时自身的坐标和大小(要获取当前点击坐标需减去上一次点击时的坐标)

            self.layer.shadowColor = [UIColor blackColor].CGColor;

            self.layer.shadowOffset = CGSizeMake(35);//设置阴影坐标

            self.layer.shadowOpacity = 1;//阴影透明度

}

//结束时

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

{


    

    self.layer.shadowColor = [UIColor clearColor].CGColor;

    self.layer.shadowOffset = CGSizeMake(0, 0);//设置阴影坐标

    self.layer.shadowOpacity = 0;//阴影透明度.

  

    //通过target 调用

    [self.target performSelector:self.selector withObject:self];//从子类中调用父类方法


    

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;//取消时

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event;//晃动(摇一摇)

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event;//晃动结束

0 0