UITouch & UIViewController
2014-07-09 21:12
141 查看
// 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.width, self.frame.size.height);//获取点击时自身的坐标和大小(要获取当前点击坐标需减去上一次点击时的坐标)
self.layer.shadowColor =
[UIColor blackColor].CGColor;
self.layer.shadowOffset = CGSizeMake(3, 5);//设置阴影坐标
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;//晃动结束
- (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.width, self.frame.size.height);//获取点击时自身的坐标和大小(要获取当前点击坐标需减去上一次点击时的坐标)
self.layer.shadowColor =
[UIColor blackColor].CGColor;
self.layer.shadowOffset = CGSizeMake(3, 5);//设置阴影坐标
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;//晃动结束
相关文章推荐
- IOS view在UIViewController中的生…
- 【UIKit-125-6】#import <UIKit/UIViewController.h>
- 【UIKit-125-7】#import <UIKit/UIViewController.h>
- 【UIKit-125-1】#import <UIKit/UIViewController.h>
- 【UIKit-125-8】#import <UIKit/UIViewController.h>
- 【UIKit-125-9】#import <UIKit/UIViewController.h>
- 【UIKit-125-2】#import <UIKit/UIViewController.h>
- "UIViewController+MethodSwizzling.h"
- 【UIKit-125-3】#import <UIKit/UIViewController.h>
- UIViewController Push & Pop 的那些坑
- Unbalanced calls to begin/end appearance transitions for <UIViewController>
- 【UIKit-125-4】#import <UIKit/UIViewController.h>
- Storyboard doesn't contain a view controller with identifier 'UIViewController'
- UIViewController.interfaceOrientation 在ios5版本下 横屏是初始化判断无效
- 关于ios的UIwindows and UIviewcontroller
- USB Redirection hack on "Two Node Controller&Compute Neutron GRE+OVS" Fedora 20 Cluster
- Using UIPageControl as a container UIViewController
- xHCI USB host controller & Debug Capability & Windows debug module
- 获得UIView对应 的viewController
- UIViewController的 modalPresentationStyle 用法