Skip to content

Instantly share code, notes, and snippets.

//
// ADBackFadeTransition.m
// AppLibrary
//
// Created by Patrick Nollet on 14/03/11.
// Copyright 2011 Applidium. All rights reserved.
//
#import "ADBackFadeTransition.h"
#import "ADDualTransition.h"
/**
* 使用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();
}
[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
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController () {
CALayer* _myLayer;
BOOL _isShowed;
BOOL _isAnimationRunning;
}
UIImageView *imageViewForAnimation = [[UIImageView alloc] initWithImage:imageToAnimate];
imageViewForAnimation.alpha = 1.0f;
CGRect imageFrame = imageViewForAnimation.frame;
//Your image frame.origin from where the animation need to get start
CGPoint viewOrigin = imageViewForAnimation.frame.origin;
viewOrigin.y = viewOrigin.y + imageFrame.size.height / 2.0f;
viewOrigin.x = viewOrigin.x + imageFrame.size.width / 2.0f;
imageViewForAnimation.frame = imageFrame;
imageViewForAnimation.layer.position = viewOrigin;
[self.view addSubview:imageViewForAnimation];