//Core Animation

#define WeakSelf __weak __typeof(self) weakSelf = self
#define StrongSelf __strong __typeof(weakSelf) self = weakSelf //添加
- (void)add:(id)sender {
[UIView animateWithDuration: animations:^{
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
}];
}
//翻页
- (void)curl:(id)sender { WeakSelf;
[UIView animateWithDuration: animations:^{
StrongSelf;
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}];
}
//移入
- (void)move:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = kCATransitionMoveIn;
trans.subtype = kCATransitionFromLeft;
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//揭开
- (void)reveal:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = kCATransitionReveal;
trans.subtype = kCATransitionFromTop;
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//立方体
- (void)cube:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = @"cube";
trans.subtype = kCATransitionFromLeft;
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//收缩
- (void)suck:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = @"suckEffect";
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//翻转
- (void)oglFlip:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = @"oglFlip";
trans.subtype = kCATransitionFromBottom;
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//水波
- (void)ripple:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = @"rippleEffect";
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}

draw default shape

    CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, );
CGContextSetRGBStrokeColor(ctx, , , , ); //straight line
const CGPoint points1[] = {CGPointMake(, ),CGPointMake(, ),CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points1, ); CGContextSetLineCap(ctx, kCGLineCapSquare);
const CGPoint points2[] = {CGPointMake(, ),CGPointMake(, ),CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points2, ); CGContextSetLineCap(ctx, kCGLineCapRound);
const CGPoint points3[] = {CGPointMake(, ),CGPointMake(, ),CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points3, ); //dashed line
CGContextSetLineCap(ctx, kCGLineCapButt);
CGContextSetLineWidth(ctx, );
CGFloat patterns1[] = {,};
CGContextSetLineDash(ctx, , patterns1, ); const CGPoint points4[] = {CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points4, ); CGContextSetLineDash(ctx, , patterns1, );
const CGPoint points5[] = {CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points5, ); CGFloat patterns2[] = {,,,,,,,,,,,,,,,,,};
CGContextSetLineDash(ctx, , patterns2, );
const CGPoint points6[] = {CGPointMake( , ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points6, ); //rectangle
CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor);
CGContextSetFillColorWithColor(ctx, [UIColor blueColor].CGColor);
CGContextSetLineWidth(ctx, );
CGContextSetLineDash(ctx, , , );//cancel dashed style
CGContextStrokeRect(ctx, CGRectMake(, , , )); CGContextSetStrokeColorWithColor(ctx, [UIColor purpleColor].CGColor);
CGContextSetLineJoin(ctx, kCGLineJoinRound);//round corner
CGContextStrokeRect(ctx, CGRectMake(, , , )); CGContextSetRGBStrokeColor(ctx, 1.0, , 1.0, );
CGContextSetLineJoin(ctx, kCGLineJoinBevel);//cliped corner
CGContextStrokeRect(ctx, CGRectMake(, ,, )); CGContextSetFillColorWithColor(ctx, [UIColor redColor].CGColor);//filled rectangle
CGContextFillRect(ctx, CGRectMake(,, , )); //oval
CGContextSetRGBStrokeColor(ctx, , , , );
CGContextStrokeEllipseInRect(ctx, CGRectMake(, , , ));//Stroke oval CGContextSetRGBFillColor(ctx, , , , );
CGContextFillEllipseInRect(ctx, CGRectMake(, , , ));//Filled oval

draw custom shape

CGContextRef ctx = UIGraphicsGetCurrentContext();//get context
for (int i = ; i < ; i++) {
CGContextBeginPath(ctx);
CGContextAddArc(ctx, i * , i * , (i + ) * , , 1.5 * M_PI, );//actually 0 means clockwise
CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, , , , ( - i) * 0.1);
CGContextFillPath(ctx);
}

draw round rect

    CGContextRef ctx = UIGraphicsGetCurrentContext();//get context

    CGContextBeginPath(ctx);

    CGFloat x,y,radius,width,height;
x = ; y = ; radius = ; width = ; height = ;
CGContextMoveToPoint(ctx, x + radius, y);//move to left top corner
CGContextAddLineToPoint(ctx, x + width - radius, y);//add top line to right top corner
CGContextAddArcToPoint(ctx, x + width, y, x + width, y + radius, radius);//add right top corner
CGContextAddLineToPoint(ctx, x + width, y + height - radius);//add right line to right bottom corner
CGContextAddArcToPoint(ctx, x + width, y + height, x + width - radius, y + height, radius);//add right bottom corner
CGContextAddLineToPoint(ctx, x + radius, y + height);//add bottom line to left bottom corner
CGContextAddArcToPoint(ctx, x, y + height, x, y + height - radius, radius);//add left bottom corner
CGContextAddLineToPoint(ctx, x, y + radius);//add left line to left top corner
CGContextAddArcToPoint(ctx, x, y, x + radius, y, radius);//add left top corner CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, , , , 0.6);
CGContextFillPath(ctx);

draw nCorner star

CGContextRef ctx = UIGraphicsGetCurrentContext();//get context

    CGContextBeginPath(ctx);

    CGFloat x,y,size;
NSInteger nCorner = ;//n corner
x = ; y = ; size = ;
CGFloat dig = * M_PI / nCorner;CGContextMoveToPoint(ctx, x, y + size);
for (int i = ; i <= nCorner; i++) {
CGFloat _x = sin(i * dig);
CGFloat _y = cos(i * dig);
CGContextAddLineToPoint(ctx, _x * size + x, _y * size + y);
} CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, , , , 0.6);
CGContextFillPath(ctx);

draw flower

CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextBeginPath(ctx);

    CGFloat x,y,size,length;
NSInteger nCorner = ;//n corner
x = ; y = ; size = ; length = ;//length should be bigger
CGContextMoveToPoint(ctx, x, y + size);
CGFloat dig = * M_PI / nCorner;
for (int i = ; i < nCorner + ; i++) {
//count control point
CGFloat ctrlX = sin((i - 0.5) * dig) * length + x;
CGFloat ctrlY = cos((i - 0.5) * dig) * length + y; //count end point
CGFloat _x = sin(i * dig) * size + x;
CGFloat _y = cos(i * dig) * size + y;
//draw line
CGContextAddQuadCurveToPoint(ctx, ctrlX, ctrlY, _x, _y);
}
CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, , , , 0.6);
CGContextFillPath(ctx);

use coordinate

CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextTranslateCTM(ctx, , );//move the coordinate
for (int i = ; i < ; i++) {
CGContextSetRGBFillColor(ctx, , , , 0.3 - i * 0.01);
CGContextFillRect(ctx, CGRectMake(, , , ));
CGContextTranslateCTM(ctx, , );
CGContextScaleCTM(ctx, 0.93, 0.93);
CGContextRotateCTM(ctx, - M_PI / ); }

最新文章

  1. java基础之 GC
  2. oracle检查点队列(checkpoint queue)
  3. TCP三次握手
  4. Indexof
  5. 深入浅出ES6(八):Symbols
  6. sqlserver convert 日期时间 转换格式化
  7. 在数据库各种状态下查询DBID的五大类十种方法汇总
  8. CentOS 5.6 安装Oracle Java 和 Eclipse
  9. Linux下安装 TestLink常见问题解决方法
  10. ORACLE输出详细错误信息错误行数
  11. (转)Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds
  12. PHP中将对数据库的操作,封装成一个工具类以及学会使用面向对象的方式进行编程
  13. android软键盘的管理和属性的设置
  14. MongoDB基础教程系列--第一篇 进入MongoDB世界
  15. ORACLE数据库学习之体系结构
  16. mac 终端里进入mysql和退出
  17. Feature Extractor[VGG]
  18. Python装饰器的调用过程
  19. Linux Samba服务主配文件smb.conf中文详解【转】
  20. C语言 &#183; 企业奖金发放

热门文章

  1. 使用XAMPP创建本地浏览器经验
  2. 去掉你代码里的 document.write(&quot;&lt;script...
  3. PHP 过滤器
  4. UI第十六节——UITabBarController详解
  5. Firefox 及其 插件“个性化设置”备份
  6. PHP计算两个时间段是否有交集(边界重叠不算)
  7. 欧拉函数 - HDU1286
  8. [codevs1105][COJ0183][NOIP2005]过河
  9. nginx自动检测后台服务器健康状态
  10. Collection接口