简单总结做个笔记,接触iOS本身也没多长时间,最近又跟android干上了,哈哈,遇到点问题对比记记,方便以后及时查看吧。之后会总觉下iOS的粒子动画效果,总算弄通了哦。粒子效果很酷。iOS的动画开发比android要简单好多哦。iOS不用CAShapLayer UIBeziearPath,就用纯画布绘制。
UIImage 和 Bitmap 很像。我在andriod和iOS 都画一个椭圆,画笔的设置其实都一样。
iOS:
UIGraphicsBeginImageContextWithOptions(CGSizeMake(10, 10), NO, 0);CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(context, CGRectMake(0, 0, 10, 10));
CGContextSetLineWidth(context, 6);
CGContextSetLineCap(context,kCGLineCapRound);
//CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
//CGContextFillPath(context);
CGContextStrokePath(context);
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
贴一个UIImageContext方法:
UIKIT_EXTERN void UIGraphicsBeginImageContext(CGSize size);
UIKIT_EXTERN void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale) NS_AVAILABLE_IOS(4_0);
UIKIT_EXTERN UIImage* UIGraphicsGetImageFromCurrentImageContext(void);
UIKIT_EXTERN void UIGraphicsEndImageContext(void);
android android的可以继承一个View或SurfaceView来进行绘制,也可以不用,事先准备好一个bitmap就行了
Paint mPaint = new Paint();
mPaint.setStrokeCap(Cap. ROUND );
mPaint.setAntiAlias( true );
mPaint.setColor(Color. BLACK );
mPaint.setStrokeWidth(3);
Bitmap mBitmap = Bitmap.createBitmap(40, 40, Config. ARGB_8888 );
Canvas mCanvas = new Canvas(mBitmap);
Rect mRect = new Rect(0, 0, 10, 10);
RectF mRectF = new RectF(mRect);
mCanvas.drawOval(mRectF, mPaint);
ImageView imageView = new ImageView( this );
imageView.setImageBitmap(mBitmap);
感觉手工画图程序极为相似,iOS使用的C语言的形式,android是Java包装过的。上面的程序很简单,我只是做个对比备忘,防止自己在两个平台交叉给忘记咯。