实现划屏效果:
UITouch类:保存手指信息(触摸的点)
开始触摸方法:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p1 = [touch locationInView:self];
CGPoint p2 = [touch previousLocationInView];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p1 = [touch locationInView:self];
CGPoint p2 = [touch previousLocationInView:self];
CGFloat x = p1.x - p2.x;
CGFloat y = p1.y - p2.y;
self.center = CGPointMake(x + self.center.x, y + self.center.y);
NSLog(@"移动中的point:%@",NSStringFromCGPoint(p1));
self.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
NSLog(@"触摸中........");
}
用presentViewController,dismissViewController 方法来跳转页面. 模态视图动画是从下面跳出来,常用于跳出一个登陆界面,
晃动方法:motionBegan:...等四个方法
用继承UIView的ButtonView的类来实现UIButton的添加方法的功能!!
1.新建一个ButtonView,继承UIView
3.在ButtonView.h中声明属性
@Proterty (strong,nonatomic)id target;
@proterty (assign,nonatomic)SEL action;
- (instancetype)initWithFrame:(CGRect)frame target:(id)target action:(SEL)action;
3.在ButtonView.h里面实现自定义初始化方法,在初始化的时候就给id target 和 SEL action 赋值
- (instancetype)initWithFrame:(CGRect)frame target:(id)target action:(SEL)action
{
self = [super initWithFrame:frame];
if(self){
self.target = target;
self.action = action;
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"点击");
self.target performSelector:self.action withObject:self];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}
先创建一个ButtonView
ButtonView *buttonView = [[ButtonView alloc] initWithFrame:CGRectMake(100, 100, 100, 50) target:self action: @selector(buttonViewClick:)];
buttonView.background =[UIColor redColor];
[self.View addSubView:buttonView];
[buttonView release];
- (void)buttonViewClick:(ButtonView *)buttonview
{
buttonview.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random() %256/ 255.0 blue:arc4random() %256/ 255.0 alpha:1];
}