小寒假第十四天总结 uitouch
来源:互联网 发布:c语言编写安卓 编辑:程序博客网 时间:2024/06/04 19:49
实现 点击图片 变化颜色 与 拖动图片
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan");
self.backgroundColor = [UIColorcolorWithRed:(arc4random() % (256))/255.0green:(arc4random() % (256))/255.0blue:(arc4random() % (256))/255.0alpha:0.6];
UITouch *touch = [touches anyObject];
_starPoint = [touch locationInView:self];
NSLog(@"point = %@",NSStringFromCGPoint(_starPoint));
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesCancelled");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesEnded");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesMoved");
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
CGFloat offSetX = currentPoint.x - _starPoint.x;
CGFloat offSetY = currentPoint.y - _starPoint.y;
NSLog(@"offSetX = %f, offSetY = %f", offSetX, offSetY);
CGPoint newCenter =self.center;
newCenter.x += offSetX;
newCenter.y += offSetY;
self.center = newCenter;
NSLog(@"currentPoint = %@", NSStringFromCGPoint(currentPoint));
}
- (id)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
[selfsetLineArray:[NSMutableArrayarrayWithCapacity:1]];
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
button.backgroundColor = [UIColorgreenColor];
button.frame =CGRectMake((frame.size.width -100) / 2, frame.size.height -50, 100, 30);
[button setTitle:@"undo"forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(undo:)forControlEvents:UIControlEventTouchUpInside];
[selfaddSubview:button];
}
return self;
}
- (void)undo:(UIButton *)button
{
[_lineArrayremoveLastObject];
[selfsetNeedsDisplay];
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
//得到上下文 绘图中需要的设置
CGContextRef context =UIGraphicsGetCurrentContext();
//设置画笔的颜色
CGContextSetStrokeColorWithColor(context, [UIColorredColor].CGColor);
//设置画笔的粗细
CGContextSetLineWidth(context,4.0);
for (int i =0; i < [_lineArraycount]; i++) {
NSMutableArray *pointArray = [_lineArrayobjectAtIndex:i];
for (int j =0; j < (int)pointArray.count -1; j++) {
NSValue *firstPointValue = [pointArray objectAtIndex:j];
NSValue *secondPointValu = [pointArray objectAtIndex:j + 1];
CGPoint firstPoint = [firstPointValue CGPointValue];
CGPoint secondPoint = [secondPointValu CGPointValue];
//把笔触移动一个点
CGContextMoveToPoint(context, firstPoint.x, firstPoint.y);
//笔触和另一个点形成一个路径
CGContextAddLineToPoint(context, secondPoint.x, secondPoint.y);
}
}
//绘制
CGContextStrokePath(context);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSMutableArray *pointArray = [NSMutableArrayarrayWithCapacity:3];
[_lineArrayaddObject:pointArray];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
NSLog(@"point = %@",NSStringFromCGPoint(point));
NSMutableArray *pointArray = [_lineArraylastObject];
NSValue *pointValue = [NSValuevalueWithCGPoint:point];
[pointArrayaddObject:pointValue];
//重绘
[selfsetNeedsDisplay];
}
- (void)dealloc
{
[_lineArray release];
[superdealloc];
}
- 小寒假第十四天总结 uitouch
- 小寒假第五天总结
- 小寒假第八天总结
- 第十四天:总结
- 第十四天总结0408
- 第十四天总结
- 连续总结第十四天
- 第十四天总结
- 小寒假第七天总结 转 Objective-C语法:
- 寒假训练的小总结
- 小寒假第二天总结
- 小寒假第四天总结
- 小寒假第六天总结
- 小寒假第六天总结
- 小寒假第十三天总结
- 森纵培训第十四天课程总结
- java学习总结——第十四天
- 第十四天
- F5负载均衡器 应用交付网络
- atitit.orm的缺点与orm框架市场占有率,选型attilax总结
- jdbc+记事本编程试水
- android ImageView scaleType属性
- POJ 2718 Smallest Difference (dfs)
- 小寒假第十四天总结 uitouch
- atitit.Windows Server 2003 2008 2012系统的新特性 attilax 总结
- atitit.自动生成数据库结构脚本,或者更换数据库,基于hibernate4
- 算法汇总
- BSP Bootloader
- 从乔布斯到库克时代,苹果发布会Keynote风格发生了哪些变化?
- NYOJ--204 Coin Test【水题】
- 【JavaScript】JavaScript基础-函数
- Mint17.1-64bit_Android开发环境配置