標籤:color art for io re c
#import "QYCustomView.h"
/*
#define HOR_SWIPE_MIN 20 //水平上,當低於這個值的時候, 不認為他是一個橫掃的手勢
#define VAR_SWIPE_MAX 40 //在垂直上,設定這誤差範圍,如果大於這個值的話, 橫掃無效
*/
@implementation QYCustomView
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
self.backgroundColor = [UIColor purpleColor];
_moveView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 30, 30)];
_moveView.backgroundColor = [UIColor redColor];
[self addSubview:_moveView];
}
return self;
}
//當我們的事件開始的時候調, 對於touch來說, 實際上當手指頭放到螢幕上的時候,這個方法會被調用
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
_moveView = [[UIView alloc ]initWithFrame:CGRectMake(0, 0, 30, 30)];
_moveView.backgroundColor = [UIColor redColor];
[self addSubview:_moveView];
}
////當我們手指點擊螢幕,並且沒有抬起而滑動的時候, 這個方法被調用, 由此可知這個方法是連續被調用的。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *tch = [touches anyObject];
CGPoint currentPoint = [tch locationInView:self];
// CGRect frame = self.moveView.frame;
self.moveView.center = currentPoint;
NSLog(@"%s",__func__);
}
//當我們的事件對束的時候調,對於touch來說, 實際上是當手指頭離開螢幕的時候,這個方法會被調用
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
/*
//
////當我們的事件被取消的時候, 比如說:手指點擊在螢幕上, 突然來電話, 這個時候, 電話的優先順序很高,
////所有的事件都應該被取消。 這個方法會被調用
//- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
//{
// NSLog(@"%s",__func__);
// self.startPoint = CGPointZero;
//}
*/
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
self.backgroundColor = [UIColor orangeColor];
}
*/
@end