iOS图形动画笔记
来源:互联网 发布:家政网络平台 编辑:程序博客网 时间:2024/05/21 10:19
1,填充背景色:
[[UIColorpurpleColor]setFill];
UIRectFill(rect);//填充背景色:
2,设置边框颜色
[[UIColorredColor]setFill];
CGRect frame =CGRectMake(20,30,100,300);
UIRectFrame(frame);//设置边框颜色
3,给图片上面增加水印或文字
重写UIView的- (void)drawRect:(CGRect)rect方法,然后将图形绘制到view上面,然后再增加文字或其他图层,如:
- (void)drawRect:(CGRect)rect
{
NSString* imagePath = [[NSBundlemainBundle]pathForResource:@"dog"ofType:@"png"];//rabbit
UIImage* myImageObj = [[UIImagealloc]initWithContentsOfFile:imagePath];
[myImageObjdrawInRect:CGRectMake(0,40,200,300)];
[myImageObjdrawAsPatternInRect:CGRectMake(0,0,320,400)];
NSString *s =@"我的小狗";
UIFont *font = [UIFontsystemFontOfSize:34];
NSDictionary *attr =@{NSFontAttributeName:font};
[drawAtPoint:CGPointMake(100,300)withAttributes:attr];
}
*,绘制曲线:
- (void)drawRect:(CGRect)rect
{
CGContextRef cgContext =UIGraphicsGetCurrentContext();//坐标
CGContextMoveToPoint(cgContext, 333, 0);
/*绘制曲线
CGContextAddCurveToPoint(cgContext, 333, 0, 332, 26, 330, 26);
CGContextAddCurveToPoint(cgContext, 330, 26, 299, 20, 299, 17);
CGContextAddLineToPoint(cgContext, 296, 17);
CGContextAddCurveToPoint(cgContext, 296, 17, 296, 19, 291, 19);
CGContextAddLineToPoint(cgContext, 250, 19);
CGContextAddCurveToPoint(cgContext, 250, 19, 241, 24, 238, 19);
CGContextAddCurveToPoint(cgContext, 236, 20, 234, 24, 227, 24);
CGContextAddCurveToPoint(cgContext, 220, 24, 217, 19, 216, 19);
CGContextAddCurveToPoint(cgContext, 214, 20, 211, 22, 207, 20);
CGContextAddCurveToPoint(cgContext, 207, 20, 187, 20, 182, 21);
CGContextAddLineToPoint(cgContext, 100, 45);
CGContextAddLineToPoint(cgContext, 97, 46);
CGContextAddCurveToPoint(cgContext, 97, 46, 86, 71, 64, 72);
CGContextAddCurveToPoint(cgContext, 42, 74, 26, 56, 23, 48);
CGContextAddLineToPoint(cgContext, 9, 47);
CGContextAddCurveToPoint(cgContext, 9, 47, 0, 31, 0, 0);
CGContextStrokePath(cgContext);
}
*,图片的缩放,平移,旋转示例
- (void)drawRect:(CGRect)rect
{
NSString *path = [[NSBundlemainBundle]pathForResource:@"cat"ofType:@"png"];
UIImage *img = [UIImageimageWithContentsOfFile:path];
CGImageRef image = img.CGImage;
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM (context,150,200);//平移
CGContextScaleCTM (context, 1.0, .75);//缩放
CGContextRotateCTM (context, radians(275.));//旋转
CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
CGContextDrawImage(context, touchRect, image);
CGContextRestoreGState(context);
}
还可以得用图层来平称图片:如:
CGAffineTransform moveTransform =CGAffineTransformMakeTranslation(180,400);
[myImageView.layersetAffineTransform:moveTransform];//平移
- iOS图形动画笔记
- ios 图形与动画学习笔记 构造路径(CGPathCreateMutable)
- iOS图形和动画处理
- iOS动画效果、绘制图形
- IOS上的图形和动画处理
- IOS上的图形和动画处理
- 简单说说iOS的图形和动画
- iOS动画技术笔记
- 【iOS动画技术笔记】
- iOS核心动画笔记
- iOS 转场动画笔记
- iOS 动画笔记
- 笔记:iOS动画
- 图形动画
- iOS动画笔记之关键帧动画
- iOS 动画类型 和 动画方向 ~笔记
- ios 动画效果CATransition笔记
- iOS动画笔记之----CAMediaTiming
- poj字符串总结
- 解决Android SDK Manager无法更新问题
- c++删除文件夹
- 控件测试第一篇
- 新手玩Linux 之 文件系统的制作
- iOS图形动画笔记
- SPI总线驱动分析
- 并查集小结
- 内核符号表和kallsyms
- 两种自定义系统弹出键盘上方的view
- 怎样成为一个软件架构师续
- HDU 3943 数位DP
- 各位acmer 学累的时候不妨来看看
- cocos2d-html5 和 cocos2d-jsb的区别