Skip to content

Instantly share code, notes, and snippets.

[self. ui_View.layer removeAllAnimations];
CABasicAnimation *pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
pulse.duration = 0.5 + (rand() % 10) * 0.05;
pulse.repeatCount = 1;
pulse.autoreverses = YES;
pulse.fromValue = [NSNumber numberWithFloat:.8];
pulse.toValue = [NSNumber numberWithFloat:1.2];
[self.ui_View.layer addAnimation:pulse forKey:nil];
// bounds
/* 过渡效果
fade //交叉淡化过渡(不支持过渡方向)
push //新视图把旧视图推出去
moveIn //新视图移到旧视图上面,
reveal //将旧视图移开,显示下面的新视图
cube //立方体翻滚效果
oglFlip //上下左右翻转效果
suckEffect //收缩效果,如一块布被抽走(不支持过渡方向)
rippleEffect //滴水效果(不支持过渡方向)
pageCurl //向上翻页效果
/**
* 使用UIKit方式生成路径
*/
///////////////////////////////////////////////////////////////////////////////////////////////////
- (CGPathRef)renderPaperCurl:(UIView*)imgView {
CGSize size = imgView.bounds.size;
CGFloat curlFactor = 12.0f;
CGFloat shadowDepth = 4.0f;
CGFloat translationFactor = 6.0f;
UIBezierPath *path = [UIBezierPath bezierPath];
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath, NULL, 15.0f, 10.0f);
CGPathAddQuadCurveToPoint(thePath, NULL, 155.0f, 450.0f, 295.0f,15.0f);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath);
CGContextSetStrokeColorWithColor(theContext, [UIColor greenColor].CGColor);
CGContextSetLineWidth(theContext, 3);
CGContextStrokePath(theContext);
CFRelease(thePath);
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,15.0f,15.f);
CGPathAddCurveToPoint(thePath,NULL,15.f,250.0f,295.0f,250.0f,295.0f,15.0f);
CGContextSetStrokeColorWithColor(theContext, [UIColor greenColor].CGColor);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath);
CGContextSetLineWidth(theContext, 5);
CGContextStrokePath(theContext);
CFRelease(thePath);
int ox = 50, oy = 50, r = 10, rw = 100, rh = 100;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL,ox, oy+r);
CGPathAddArcToPoint(path, NULL, ox, oy+rh, ox+r,oy+rh, r);
CGPathAddArcToPoint(path, NULL, ox+rw, oy+rh, ox+rw, oy+rh-r, r);
CGPathAddArcToPoint(path, NULL, ox+rw, oy, ox+rw-r, oy, r);
CGPathAddArcToPoint(path, NULL, ox, oy, ox,oy+r,r);
CGContextSetStrokeColorWithColor(theContext, [UIColor greenColor].CGColor);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, path);
static inline double radians (double degrees) { return degrees * M_PI/180; }
@implementation MyLayerDelegate
- (void)drawLayer:(CALayer *)theLayer inContext:(CGContextRef)theContext {
CGContextSetStrokeColorWithColor(theContext, [UIColor greenColor].CGColor);
CGMutablePathRef path = createArcPathFromBottomOfRect(CGRectMake(0, 0, 100, 100), 50.0f);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, path);
CGContextSetLineWidth(theContext, 3);
CGContextStrokePath(theContext);
CFRelease(path);
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(ctx);
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); // white color
CGContextSetShadow(ctx, CGSizeMake(2.0f, 2.0f), 2.0f); //也可以使用CGContextSetShadowWithColor (myContext, myShadowOffset, 5, myColor);
CGContextFillEllipseInRect(ctx, CGRectMake(10.0f, 10.0f, 100.0f, 100.0f)); // a white filled circle with a diameter of 100 pixels, centered in (60, 60)
UIGraphicsPopContext();
}
#define NavigationBar_HEIGHT 44
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define SAFE_RELEASE(x) [x release];x=nil
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
#define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]
//use dlog to print while in debug model
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController () {
CALayer* _myLayer;
BOOL _isShowed;
BOOL _isAnimationRunning;
}