12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418 |
- //
- // QuickUIUtil.swift
- // CommonUtil
- //
- // Created by lijunjie on 15/11/14.
- // Copyright © 2015年 lijunjie. All rights reserved.
- //
- import Foundation
- public class QuickUIUtil {
-
- static let share = QuickUIUtil()
-
- private init () {}
-
- public func colorFromRed(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
- return self.colorFromRed(red: red, green: green, blue: blue, alpha: 1.0)
- }
-
- public func colorFromRed(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> UIColor {
- return UIColor(red: red/255.0, green: green/255.0, blue: blue/255.0, alpha: alpha)
- }
-
- public func colorFromHexString(hexString: String) -> UIColor {
- return self.colorFromHexString(hexString: hexString, alpha: 1.0)
- }
-
- public func colorFromHexString(hexString: String, alpha: CGFloat) -> UIColor {
- var hexNum: UInt32 = 0
- Scanner(string: hexString).scanHexInt32(&hexNum)
- return UIColor(red: ((CGFloat)((hexNum & 0xFF0000) >> 16))/255.0 , green: ((CGFloat)((hexNum & 0xFF00) >> 8))/255.0, blue: ((CGFloat)(hexNum & 0xFF))/255.0, alpha: alpha)
- }
-
- //
- // + (CGContextRef)getTextCTMContextRefFromView:(UIView *)aView
- // {
- // if (CUCFCheckObjectNull(aView)) {
- // return nil
- // }
- //
- // /* 获取图形上下文 */
- // CGContextRef context = UIGraphicsGetCurrentContext()
- //
- // /* 变换矩阵 */
- // CGContextTranslateCTM(context, 0, aView.bounds.size.height)
- // CGContextScaleCTM(context, 1, -1.0)
- //
- // /* 设置文字绘制矩阵 */
- // CGContextSetTextMatrix(context, CGAffineTransformIdentity)
- //
- // return context
- // }
- //
- // /* 根据颜色创建图片 */
- // + (UIImage *)imageForColor:(UIColor*)aColor withSize:(CGSize)aSize
- // {
- // if (CUCFCheckObjectNull(aColor)) {
- // return nil
- // }
- //
- // CGRect rect = CGRectMake(0, 0, aSize.width, aSize.height)
- //
- // UIGraphicsBeginImageContext(rect.size)
- //
- // CGContextRef context = UIGraphicsGetCurrentContext()
- //
- // CGContextSetFillColorWithColor(context, aColor.CGColor)
- //
- // CGContextFillRect(context, rect)
- //
- // UIImage *img = UIGraphicsGetImageFromCurrentImageContext()
- //
- // UIGraphicsEndImageContext()
- //
- // return img
- // }
- //
- // + (UIImage *)viewScreenShot:(UIView *)aView
- // {
- // return [CUCFQuickUIUitil layerScreenShot:aView.layer]
- // }
- //
- // + (UIImage *)layerScreenShot:(CALayer *)layer
- // {
- // if (CUCFCheckObjectNull(layer)) {
- // return nil
- // }
- //
- // UIGraphicsBeginImageContextWithOptions(layer.bounds.size, layer.opaque, 0.0f)
- // [layer renderInContext:UIGraphicsGetCurrentContext()]
- // UIImage* image = UIGraphicsGetImageFromCurrentImageContext()
- // UIGraphicsEndImageContext()
- // return image
- // }
- //
- // + (UIImage *)combineImage:(UIImage *)backgroundImage withMaskImage:(UIImage *)maskImage
- // {
- // if (CUCFCheckObjectNull(backgroundImage)) {
- // return nil
- // }
- // UIGraphicsBeginImageContext(backgroundImage.size)
- //
- // // 绘制改变大小的图片
- // CGRect newImageFrame = CGRectMake(0, 0,backgroundImage.size.width, backgroundImage.size.height)
- //
- // [backgroundImage drawInRect:newImageFrame]
- //
- // CGFloat originX = (newImageFrame.size.width - maskImage.size.width)/2
- // CGFloat originY = (newImageFrame.size.height - maskImage.size.height)/2
- //
- // CGRect maskImageFrame = CGRectMake(originX, originY, maskImage.size.width, maskImage.size.height)
- //
- // [maskImage drawInRect:maskImageFrame]
- //
- // UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext()
- //
- // UIGraphicsEndImageContext()
- //
- // return scaledImage
- //
- // }
- //
- // + (UIImage *)fixOretationImage:(UIImage *)aImage
- // {
- // if (!aImage) {
- // return nil
- // }
- //
- // // 正确的方向
- // if (aImage.imageOrientation == UIImageOrientationUp){
- //
- // CGSize scaleSize = aImage.size
- //
- // UIGraphicsBeginImageContext(scaleSize)
- //
- // // 绘制改变大小的图片
- // [aImage drawInRect:CGRectMake(0, 0, scaleSize.width, scaleSize.height)]
- //
- // UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext()
- //
- // UIGraphicsEndImageContext()
- //
- // return scaledImage
- // }
- //
- // // 错误的方向
- // CGAffineTransform transform = CGAffineTransformIdentity
- //
- // switch (aImage.imageOrientation) {
- // case UIImageOrientationDown:
- // case UIImageOrientationDownMirrored:
- // transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height)
- // transform = CGAffineTransformRotate(transform, M_PI)
- // break
- //
- // case UIImageOrientationLeft:
- // case UIImageOrientationLeftMirrored:
- // transform = CGAffineTransformTranslate(transform, aImage.size.width, 0)
- // transform = CGAffineTransformRotate(transform, M_PI_2)
- // break
- //
- // case UIImageOrientationRight:
- // case UIImageOrientationRightMirrored:
- // transform = CGAffineTransformTranslate(transform, 0, aImage.size.height)
- // transform = CGAffineTransformRotate(transform, -M_PI_2)
- // break
- // case UIImageOrientationUp:
- // case UIImageOrientationUpMirrored:
- // break
- // }
- //
- // switch (aImage.imageOrientation) {
- // case UIImageOrientationUpMirrored:
- // case UIImageOrientationDownMirrored:
- // transform = CGAffineTransformTranslate(transform, aImage.size.width, 0)
- // transform = CGAffineTransformScale(transform, -1, 1)
- // break
- //
- // case UIImageOrientationLeftMirrored:
- // case UIImageOrientationRightMirrored:
- // transform = CGAffineTransformTranslate(transform, aImage.size.height, 0)
- // transform = CGAffineTransformScale(transform, -1, 1)
- // break
- // case UIImageOrientationUp:
- // case UIImageOrientationDown:
- // case UIImageOrientationLeft:
- // case UIImageOrientationRight:
- // break
- // }
- //
- // CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
- // CGImageGetBitsPerComponent(aImage.CGImage), 0,
- // CGImageGetColorSpace(aImage.CGImage),
- // CGImageGetBitmapInfo(aImage.CGImage))
- // CGContextConcatCTM(ctx, transform)
- // switch (aImage.imageOrientation) {
- // case UIImageOrientationLeft:
- // case UIImageOrientationLeftMirrored:
- // case UIImageOrientationRight:
- // case UIImageOrientationRightMirrored:
- //
- // CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage)
- // break
- //
- // default:
- // CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage)
- // break
- // }
- //
- // // 创建一张新图
- // CGImageRef cgimg = CGBitmapContextCreateImage(ctx)
- // UIImage *img = [UIImage imageWithCGImage:cgimg]
- // CGContextRelease(ctx)
- // CGImageRelease(cgimg)
- //
- // return img
- // }
- //
- // + (UIImage *)partImage:(UIImage *)aImage withRect:(CGRect)partRect
- // {
- // if (CUCFCheckObjectNull(aImage)) {
- // return nil
- // }
- //
- // CGImageRef imager = CGImageCreateWithImageInRect(aImage.CGImage,partRect)
- //
- // UIImage *partImage = [UIImage imageWithCGImage:imager]
- //
- // CGImageRelease(imager)
- //
- // return partImage
- //
- // }
- //
- // + (UIImage *)correctFullSolutionImageFromALAsset:(ALAsset *)asset withScaleSize:(CGFloat)scaleSize
- // {
- // if (CUCFCheckObjectNull(asset)) {
- // return nil
- // }
- //
- // ALAssetRepresentation *defaultReprensent = [asset defaultRepresentation]
- //
- // UIImage *fullSolutionImage = [UIImage imageWithCGImage:defaultReprensent.fullResolutionImage scale:1.0 orientation:(UIImageOrientation)[defaultReprensent orientation]]
- //
- // return [CUCFQuickUIUitil correctImageOrientation:fullSolutionImage withScaleSize:scaleSize]
- // }
- //
- // + (UIImage *)correctFullSolutionImageFromALAsset:(ALAsset *)asset
- // {
- // return [CUCFQuickUIUitil correctFullSolutionImageFromALAsset:asset withScaleSize:1.0]
- // }
- //
- // + (UIImage *)correctImageOrientation:(UIImage *)aImage
- // {
- // return [CUCFQuickUIUitil correctImageOrientation:aImage withScaleSize:1.0]
- // }
- //
- // + (UIImage *)correctImageOrientation:(UIImage *)aImage withScaleSize:(CGFloat)scale
- // {
- // if (CUCFCheckObjectNull(aImage)) {
- // return nil
- // }
- //
- // // 正确的方向
- // if (aImage.imageOrientation == UIImageOrientationUp){
- //
- // CGSize scaleSize = CGSizeMake(aImage.size.width * scale, aImage.size.height * scale)
- //
- // UIGraphicsBeginImageContext(scaleSize)
- //
- // // 绘制改变大小的图片
- // [aImage drawInRect:CGRectMake(0, 0, scaleSize.width, scaleSize.height)]
- //
- // UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext()
- //
- // UIGraphicsEndImageContext()
- //
- // return scaledImage
- // }
- //
- // // 错误的方向
- // CGAffineTransform transform = CGAffineTransformIdentity
- //
- // switch (aImage.imageOrientation) {
- // case UIImageOrientationDown:
- // case UIImageOrientationDownMirrored:
- // transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height)
- // transform = CGAffineTransformRotate(transform, M_PI)
- // break
- //
- // case UIImageOrientationLeft:
- // case UIImageOrientationLeftMirrored:
- // transform = CGAffineTransformTranslate(transform, aImage.size.width, 0)
- // transform = CGAffineTransformRotate(transform, M_PI_2)
- // break
- //
- // case UIImageOrientationRight:
- // case UIImageOrientationRightMirrored:
- // transform = CGAffineTransformTranslate(transform, 0, aImage.size.height)
- // transform = CGAffineTransformRotate(transform, -M_PI_2)
- // break
- // case UIImageOrientationUp:
- // case UIImageOrientationUpMirrored:
- // break
- // }
- //
- // switch (aImage.imageOrientation) {
- // case UIImageOrientationUpMirrored:
- // case UIImageOrientationDownMirrored:
- // transform = CGAffineTransformTranslate(transform, aImage.size.width, 0)
- // transform = CGAffineTransformScale(transform, -1, 1)
- // break
- //
- // case UIImageOrientationLeftMirrored:
- // case UIImageOrientationRightMirrored:
- // transform = CGAffineTransformTranslate(transform, aImage.size.height, 0)
- // transform = CGAffineTransformScale(transform, -1, 1)
- // break
- // case UIImageOrientationUp:
- // case UIImageOrientationDown:
- // case UIImageOrientationLeft:
- // case UIImageOrientationRight:
- // break
- // }
- //
- // CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
- // CGImageGetBitsPerComponent(aImage.CGImage), 0,
- // CGImageGetColorSpace(aImage.CGImage),
- // CGImageGetBitmapInfo(aImage.CGImage))
- // CGContextConcatCTM(ctx, transform)
- // switch (aImage.imageOrientation) {
- // case UIImageOrientationLeft:
- // case UIImageOrientationLeftMirrored:
- // case UIImageOrientationRight:
- // case UIImageOrientationRightMirrored:
- //
- // CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage)
- // break
- //
- // default:
- // CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage)
- // break
- // }
- //
- // // 创建一张新图
- // CGImageRef cgimg = CGBitmapContextCreateImage(ctx)
- // UIImage *img = [UIImage imageWithCGImage:cgimg]
- // CGContextRelease(ctx)
- // CGImageRelease(cgimg)
- //
- // CGSize scaleSize = CGSizeMake(aImage.size.width * scale, aImage.size.height * scale)
- //
- // UIGraphicsBeginImageContext(scaleSize)
- //
- // // 绘制改变大小的图片
- // [img drawInRect:CGRectMake(0, 0, scaleSize.width, scaleSize.height)]
- //
- // UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext()
- //
- // UIGraphicsEndImageContext()
- //
- // return scaledImage
- //
- // }
- //
- // + (UIImage *)roundImage:(UIImage *)aImage
- // {
- // if (CUCFCheckObjectNull(aImage)) {
- // return nil
- // }
- //
- // /* 取最小边,否则会出现椭圆 */
- // CGFloat itemWidth = MIN(aImage.size.width, aImage.size.height)
- //
- // //取中心
- // CGFloat originX = (aImage.size.width - itemWidth)/2
- // CGFloat originY = (aImage.size.height - itemWidth)/2
- // CGRect imageRect = (CGRect){originX,originY,itemWidth,itemWidth}
- // aImage = [CUCFQuickUIUitil partImage:aImage withRect:imageRect]
- // imageRect.origin = CGPointZero;//恢复
- //
- // UIGraphicsBeginImageContextWithOptions((CGSize){itemWidth,itemWidth}, 1.0, 0.0f)
- //
- // CGColorSpaceRef maskColorSpaceRef = CGColorSpaceCreateDeviceGray()
- // CGContextRef mainMaskContextRef = CGBitmapContextCreate(NULL,
- // imageRect.size.width,
- // imageRect.size.height,
- // 8,
- // imageRect.size.width,
- // maskColorSpaceRef,
- // 0)
- // CGContextFillRect(mainMaskContextRef, imageRect)
- // CGContextSetFillColorWithColor(mainMaskContextRef,[UIColor whiteColor].CGColor)
- //
- // // Create main mask shape
- // CGContextMoveToPoint(mainMaskContextRef, 0, 0)
- // CGContextAddEllipseInRect(mainMaskContextRef, imageRect)
- // CGContextFillPath(mainMaskContextRef)
- //
- // CGImageRef mainMaskImageRef = CGBitmapContextCreateImage(mainMaskContextRef)
- // CGContextRelease(mainMaskContextRef)
- //
- // CGContextRef contextRef = UIGraphicsGetCurrentContext()
- // CGContextSaveGState(contextRef)
- //
- // CGImageRef imageRef = CGImageCreateWithMask(aImage.CGImage, mainMaskImageRef)
- //
- // CGContextTranslateCTM(contextRef, 0, imageRect.size.height)
- // CGContextScaleCTM(contextRef, 1.0, -1.0)
- //
- // CGContextSaveGState(contextRef)
- //
- //
- // UIImage* image = [UIImage imageWithCGImage:imageRef]
- //
- // CGImageRelease(imageRef)
- // CGImageRelease(mainMaskImageRef)
- //
- // UIGraphicsEndImageContext()
- //
- // return image
- // }
- //
- // + (UIImage *)imageWithName:(NSString *)imageName
- // {
- // if (CUCFStringIsNull(imageName)) {
- // return nil
- // }
- // return [UIImage imageNamed:imageName]
- // }
- //
- // + (UIImage *)imageWithFilePath:(NSString *)filePath
- // {
- // if (CUCFStringIsNull(filePath)) {
- // return nil
- // }
- // return [UIImage imageWithContentsOfFile:filePath]
- // }
- //
- // + (UIImage *)imageUnArchievedFromFilePath:(NSString *)filePath
- // {
- // return CUCFUnArchieveObject(filePath)
- // }
- //
- // + (UIImage *)gradientLinearImageFromColor:(UIColor *)fromColor withToColor:(UIColor *)toColor withImageSize:(CGSize)size
- // {
- // return [CUCFQuickUIUitil gradientLinearImageFromColors:@[fromColor,toColor,fromColor] withImageSize:size]
- // }
- //
- // + (UIImage *)gradientLinearImageFromColors:(NSArray *)colors withImageSize:(CGSize)size
- // {
- // if (CUCFCheckObjectNull(colors)) {
- // return nil
- // }
- //
- // UIGraphicsBeginImageContext(size)
- //
- // CGContextRef context = UIGraphicsGetCurrentContext()
- //
- // CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB()
- //
- // CGFloat _locations[] = {0.f,0.5f,1.f}
- //
- // NSMutableArray *_colors = [NSMutableArray array]
- //
- // id fromColor = nil
- // if (colors.count >= 1) {
- // fromColor = (__bridge id)[(UIColor *)[colors objectAtIndex:0] CGColor]
- // }
- //
- // id toColor = nil
- // if (colors.count >= 2) {
- // toColor = (__bridge id)[(UIColor *)[colors objectAtIndex:1] CGColor]
- // }
- //
- // id endColor = nil
- // if (colors.count == 3) {
- // endColor = (__bridge id)[(UIColor *)[colors objectAtIndex:2] CGColor]
- // }
- //
- // if (fromColor) {
- // [_colors addObject:fromColor]
- // }
- // if (toColor) {
- // [_colors addObject:toColor]
- // }
- // if (endColor) {
- // [_colors addObject:endColor]
- // }
- //
- // CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)_colors, _locations)
- //
- // CGPoint startPoint = CGPointMake(floorf(size.width), 0)
- //
- // CGPoint endPoint = CGPointMake(floorf(size.width), size.height)
- //
- // CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0)
- //
- // CFRelease(gradient)
- //
- // CFRelease(colorSpace)
- //
- // UIImage *gradientImage = UIGraphicsGetImageFromCurrentImageContext()
- //
- // UIGraphicsEndImageContext()
- //
- // return gradientImage
- //
- // }
- //
- // + (UIImage *)gradientRadialImageFromColor:(UIColor *)fromColor withToColor:(UIColor *)toColor withImageSize:(CGSize)size
- // {
- // return [CUCFQuickUIUitil gradientRadialImageFromColors:@[fromColor,toColor] withImageSize:size]
- // }
- //
- // + (UIImage *)gradientRadialImageFromColors:(NSArray *)colors withImageSize:(CGSize)size
- // {
- // if (CUCFCheckObjectNull(colors)) {
- // return nil
- // }
- //
- // UIGraphicsBeginImageContext(size)
- //
- // CGContextRef context = UIGraphicsGetCurrentContext()
- //
- // CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB()
- //
- // CGFloat _locations[] = {0.f,0.5,1.f}
- //
- // NSMutableArray *_colors = [NSMutableArray array]
- //
- // id fromColor = nil
- // if (colors.count >= 1) {
- // fromColor = (__bridge id)[(UIColor *)[colors objectAtIndex:0] CGColor]
- // }
- //
- // id toColor = nil
- // if (colors.count >= 2) {
- // toColor = (__bridge id)[(UIColor *)[colors objectAtIndex:1] CGColor]
- // }
- //
- // id endColor = nil
- // if (colors.count == 3) {
- // endColor = (__bridge id)[(UIColor *)[colors objectAtIndex:2] CGColor]
- // }
- //
- // if (fromColor) {
- // [_colors addObject:fromColor]
- // }
- // if (toColor) {
- // [_colors addObject:toColor]
- // }
- // if (endColor) {
- // [_colors addObject:endColor]
- // }
- //
- // CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)_colors, _locations)
- //
- // CGPoint startPoint = CGPointMake(floorf(size.width/2), size.height/2)
- //
- // CGFloat radius = MIN(size.width/2, size.height/2)
- // CGContextDrawRadialGradient(context, gradient, startPoint, 0, startPoint,radius, kCGGradientDrawsBeforeStartLocation|kCGGradientDrawsAfterEndLocation)
- //
- // CFRelease(gradient)
- //
- // CFRelease(colorSpace)
- //
- // UIImage *gradientImage = UIGraphicsGetImageFromCurrentImageContext()
- //
- // UIGraphicsEndImageContext()
- //
- // return gradientImage
- // }
- //
- // + (UIImage *)gridImageHorizonByLineGap:(CGFloat)lineGap withLineColor:(UIColor *)lineColor withImageSize:(CGSize)size
- // {
- // return [CUCFQuickUIUitil gridImageByHoriLineGap:lineGap withVerticalLineGap:0.f withLineColor:lineColor withImageSize:size]
- // }
- //
- // + (UIImage *)gridImageVerticalByLineGap:(CGFloat)lineGap withLineColor:(UIColor *)lineColor withImageSize:(CGSize)size
- // {
- // return [CUCFQuickUIUitil gridImageByHoriLineGap:0.f withVerticalLineGap:lineGap withLineColor:lineColor withImageSize:size]
- // }
- //
- // + (UIImage *)gridImageByHoriLineGap:(CGFloat)hLineGap withVerticalLineGap:(CGFloat)vLineGap withLineColor:(UIColor *)lineColor withImageSize:(CGSize)size
- // {
- // CGFloat width = size.width
- // CGFloat height = size.height
- //
- // UIGraphicsBeginImageContext(CGSizeMake(width, height))
- // CGContextRef context = UIGraphicsGetCurrentContext()
- //
- // CGContextSetStrokeColorWithColor(context, lineColor.CGColor)
- //
- // if (hLineGap > 0.f) {
- //
- // for (int y=0; y < height; y=y+hLineGap) {
- //
- // CGContextBeginPath(context)
- //
- // CGContextMoveToPoint(context, 0, y)
- //
- // CGContextAddLineToPoint(context, width, y)
- //
- // CGContextStrokePath(context)
- // }
- // }
- //
- // if (vLineGap > 0.f) {
- //
- // for (int x=0; x<width; x=x+vLineGap) {
- //
- // CGContextBeginPath(context)
- //
- // CGContextMoveToPoint(context, x, 0)
- //
- // CGContextAddLineToPoint(context, x, height)
- //
- // CGContextStrokePath(context)
- // }
- // }
- //
- //
- // UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext()
- // UIGraphicsEndImageContext()
- //
- // return newImage
- //
- // }
- //
- // + (UIImage *)stretchImage:(UIImage *)originImage withTopOffset:(CGFloat)top withLeftOffset:(CGFloat)left
- // {
- // if (CUCFCheckObjectNull(originImage)) {
- // return nil
- // }
- // return [originImage stretchableImageWithLeftCapWidth:left topCapHeight:top]
- // }
- //
- // + (UIImage *)resizeImage:(UIImage *)originImage withEdgeTop:(CGFloat)top withEdgeBottom:(CGFloat)bottom withEdgeLeft:(CGFloat)left withEdgeRight:(CGFloat)right
- // {
- // if (CUCFCheckObjectNull(originImage)) {
- // return nil
- // }
- // return [originImage resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch]
- // }
- //
- // + (void)animationDuration:(NSTimeInterval)duration action:(dispatch_block_t)block
- // {
- // [CUCFQuickUIUitil animationDelay:0 animationDuration:duration action:block]
- // }
- //
- // + (void)animationDelay:(NSTimeInterval )delaySecond animationDuration:(NSTimeInterval)duration action:(dispatch_block_t)block
- // {
- // if (CUCFCheckObjectNull(block)) {
- // return
- // }
- //
- // CUCFAsyncMainQueueDelay(delaySecond, ^{
- //
- // [UIView animateWithDuration:duration animations:block]
- //
- // })
- // }
- //
- // + (void)animationView:(UIView *)view withDuration:(NSTimeInterval)duration action:(dispatch_block_t)block withOptions:(UIViewAnimationOptions)options completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // [CUCFQuickUIUitil animationView:view delay:0 animationDuration:duration action:block withOptions:options completionBlock:completion]
- // }
- //
- // + (void)animationView:(UIView *)view delay:(NSTimeInterval)delaySecond animationDuration:(NSTimeInterval)duration action:(dispatch_block_t)block withOptions:(UIViewAnimationOptions)options completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- // [UIView transitionWithView:view duration:duration options:options animations:block completion:completion]
- // }
- //
- // + (void)defaultHiddenShowView:(UIView *)view
- // {
- // [CUCFQuickUIUitil hiddenShowView:view withDuration:0.3]
- // }
- //
- // + (void)defaultShowHiddenView:(UIView *)view
- // {
- // [CUCFQuickUIUitil showHiddenView:view withDuration:0.3]
- // }
- //
- // + (void)defaultHiddenView:(UIView *)view
- // {
- // [CUCFQuickUIUitil hiddenView:view withDuration:0.3]
- // }
- //
- // + (void)defaultShowView:(UIView *)view
- // {
- // [CUCFQuickUIUitil showView:view withDuration:0.3]
- // }
- //
- // + (void)hiddenView:(UIView *)view withDuration:(NSTimeInterval)duration
- // {
- // [CUCFQuickUIUitil animationView:view fromAlpha:view.alpha toAlpha:0 withDuration:duration]
- // }
- //
- // + (void)showView:(UIView *)view withDuration:(NSTimeInterval)duration
- // {
- // [CUCFQuickUIUitil animationView:view fromAlpha:view.alpha toAlpha:1 withDuration:duration]
- // }
- //
- // + (void)showView:(UIView *)view finalAlpha:(CGFloat)alpha withDuration:(NSTimeInterval)duration
- // {
- // [CUCFQuickUIUitil animationView:view fromAlpha:view.alpha toAlpha:alpha withDuration:duration]
- // }
- //
- // + (void)hiddenShowView:(UIView *)view withDuration:(NSTimeInterval)duration
- // {
- // [CUCFQuickUIUitil animationView:view fromAlpha:0 toAlpha:1 withDuration:duration]
- // }
- //
- // + (void)showHiddenView:(UIView *)view withDuration:(NSTimeInterval)duration
- // {
- // [CUCFQuickUIUitil animationView:view fromAlpha:1 toAlpha:0 withDuration:duration]
- // }
- //
- // + (void)animationView:(UIView *)view fromAlpha:(CGFloat)fAlpha toAlpha:(CGFloat)tAlpha withDuration:(NSTimeInterval)duration
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- //
- // view.alpha = fAlpha
- //
- // CUCFAnimationWithDuration(duration, ^{
- //
- // view.alpha = tAlpha
- //
- // })
- // }
- //
- // + (void)moveView:(UIView *)view newRect:(CGRect)rect withDuration:(NSTimeInterval)duration
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- //
- // if (CGRectEqualToRect(view.frame, rect)) {
- // return
- // }
- //
- // CUCFAnimationWithDuration(duration, ^{
- //
- // view.frame = rect
- //
- // })
- // }
- //
- // + (void)moveViewX:(UIView *)view originXDetal:(CGFloat)moveX withDuration:(NSTimeInterval)duration
- // {
- // [CUCFQuickUIUitil moveView:view originXDetal:moveX originYDetal:0.f widthDetal:0.f heightDetla:0.f withDuration:duration]
- // }
- //
- // + (void)moveViewY:(UIView *)view originYDetal:(CGFloat)moveY withDuration:(NSTimeInterval)duration
- // {
- // [CUCFQuickUIUitil moveView:view originXDetal:0.f originYDetal:moveY widthDetal:0.f heightDetla:0.f withDuration:duration]
- // }
- //
- // + (void)moveViewWidth:(UIView *)view widthDetal:(CGFloat)moveWidth withDuration:(NSTimeInterval)duration
- // {
- // [CUCFQuickUIUitil moveView:view originXDetal:0.f originYDetal:0.f widthDetal:moveWidth heightDetla:0.f withDuration:duration]
- // }
- //
- // + (void)moveViewHeight:(UIView *)view heightDetal:(CGFloat)moveHeight withDuration:(NSTimeInterval)duration
- // {
- // [CUCFQuickUIUitil moveView:view originXDetal:0.f originYDetal:0.f widthDetal:0.f heightDetla:moveHeight withDuration:duration]
- // }
- //
- // + (void)moveViewToX:(UIView *)view toOriginX:(CGFloat)moveX withDuration:(NSTimeInterval)duration
- // {
- // CGFloat detal = moveX - view.frame.origin.x
- // [CUCFQuickUIUitil moveViewX:view originXDetal:detal withDuration:duration]
- // }
- //
- // + (void)moveViewToY:(UIView *)view toOriginY:(CGFloat)moveY withDuration:(NSTimeInterval)duration
- // {
- // CGFloat detal = moveY - view.frame.origin.y
- // [CUCFQuickUIUitil moveViewY:view originYDetal:detal withDuration:duration]
- // }
- //
- // + (void)moveViewToWidth:(UIView *)view toWidth:(CGFloat)moveWidth withDuration:(NSTimeInterval)duration
- // {
- // CGFloat detal = moveWidth - view.frame.size.width
- // [CUCFQuickUIUitil moveViewWidth:view widthDetal:detal withDuration:duration]
- // }
- //
- // + (void)moveViewToHeight:(UIView *)view toHeight:(CGFloat)moveHeight withDuration:(NSTimeInterval)duration
- // {
- // CGFloat detal = moveHeight - view.frame.size.height
- // [CUCFQuickUIUitil moveViewHeight:view heightDetal:detal withDuration:duration]
- // }
- //
- // + (void)moveViewCenter:(UIView *)view newCenter:(CGPoint)center withDuration:(NSTimeInterval)duration
- // {
- // CUCFAnimationWithDuration(duration, ^{
- //
- // view.center = center
- //
- // })
- // }
- //
- // + (void)moveViewSize:(UIView *)view newSize:(CGSize)size withDuration:(NSTimeInterval)duration
- // {
- // CGRect newFrame = view.frame
- // newFrame.size = size
- // CUCFAnimationMoveViewRect(view, newFrame, duration)
- // }
- //
- // + (void)moveView:(UIView *)view originXDetal:(CGFloat)moveX originYDetal:(CGFloat)moveY widthDetal:(CGFloat)moveWidth heightDetla:(CGFloat)moveHeight withDuration:(NSTimeInterval)duration
- // {
- // CGRect newFrame = view.frame
- // newFrame.origin.x = newFrame.origin.x + moveX
- // newFrame.origin.y = newFrame.origin.y + moveY
- // newFrame.size.width = newFrame.size.width + moveWidth
- // newFrame.size.height = newFrame.size.height + moveHeight
- //
- // [CUCFQuickUIUitil moveView:view newRect:newFrame withDuration:duration]
- // }
- //
- // + (void)flipViewFromLeft:(UIView *)view withDuration:(NSTimeInterval)duration action:(dispatch_block_t)block completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // [CUCFQuickUIUitil flipView:view fromLeft:YES fromRight:NO fromTop:NO fromBottom:NO action:block withDuration:duration completionBlock:completion]
- // }
- //
- // + (void)flipViewFromRight:(UIView *)view withDuration:(NSTimeInterval)duration action:(dispatch_block_t)block completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // [CUCFQuickUIUitil flipView:view fromLeft:NO fromRight:YES fromTop:NO fromBottom:NO action:block withDuration:duration completionBlock:completion]
- // }
- //
- // + (void)flipViewFromTop:(UIView *)view withDuration:(NSTimeInterval)duration action:(dispatch_block_t)block completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // [CUCFQuickUIUitil flipView:view fromLeft:NO fromRight:NO fromTop:YES fromBottom:NO action:block withDuration:duration completionBlock:completion]
- // }
- //
- // + (void)flipViewFromBottom:(UIView *)view withDuration:(NSTimeInterval)duration action:(dispatch_block_t)block completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // [CUCFQuickUIUitil flipView:view fromLeft:NO fromRight:NO fromTop:NO fromBottom:YES action:block withDuration:duration completionBlock:completion]
- // }
- //
- // + (void)flipView:(UIView *)view fromLeft:(BOOL)isLeft fromRight:(BOOL)isRight fromTop:(BOOL)isTop fromBottom:(BOOL)isBottom action:(dispatch_block_t)block withDuration:(NSTimeInterval)duration completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- // if (isLeft) {
- // [CUCFQuickUIUitil animationView:view withDuration:duration action:block withOptions:UIViewAnimationOptionTransitionFlipFromLeft completionBlock:completion]
- // }
- // if (isRight) {
- // [CUCFQuickUIUitil animationView:view withDuration:duration action:block withOptions:UIViewAnimationOptionTransitionFlipFromRight completionBlock:completion]
- // }
- // if (isTop) {
- // [CUCFQuickUIUitil animationView:view withDuration:duration action:block withOptions:UIViewAnimationOptionTransitionFlipFromTop completionBlock:completion]
- // }
- // if (isBottom) {
- // [CUCFQuickUIUitil animationView:view withDuration:duration action:block withOptions:UIViewAnimationOptionTransitionFlipFromBottom completionBlock:completion]
- // }
- // }
- //
- // + (void)pageUpViewFromBottom:(UIView *)view withDuration:(NSTimeInterval)duration action:(dispatch_block_t)block completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // [CUCFQuickUIUitil pageUpView:view fromLeft:NO fromRight:NO fromTop:NO fromBottom:YES action:block withDuration:duration completionBlock:completion]
- // }
- //
- // + (void)pageUpView:(UIView *)view fromLeft:(BOOL)isLeft fromRight:(BOOL)isRight fromTop:(BOOL)isTop fromBottom:(BOOL)isBottom action:(dispatch_block_t)block withDuration:(NSTimeInterval)duration completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- // if (isBottom) {
- // [CUCFQuickUIUitil animationView:view withDuration:duration action:block withOptions:UIViewAnimationOptionTransitionCurlUp|UIViewAnimationOptionCurveEaseInOut completionBlock:completion]
- // }
- // }
- //
- // + (void)pageDownViewFromTop:(UIView *)view withDuration:(NSTimeInterval)duration action:(dispatch_block_t)block completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // [CUCFQuickUIUitil pageDownView:view fromLeft:NO fromRight:NO fromTop:YES fromBottom:NO action:block withDuration:duration completionBlock:completion]
- // }
- //
- // + (void)pageDownView:(UIView *)view fromLeft:(BOOL)isLeft fromRight:(BOOL)isRight fromTop:(BOOL)isTop fromBottom:(BOOL)isBottom action:(dispatch_block_t)block withDuration:(NSTimeInterval)duration completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- // if (isTop) {
- // [CUCFQuickUIUitil animationView:view withDuration:duration action:block withOptions:UIViewAnimationOptionTransitionCurlDown|UIViewAnimationOptionCurveEaseInOut completionBlock:completion]
- // }
- // }
- //
- // + (void)cubeView:(UIView *)view withDuration:(NSTimeInterval)duration action:(dispatch_block_t)block completionBlock:(CUCFQuickAnimationCompletionBlock)completion
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- // [CUCFQuickUIUitil animationView:view withDuration:duration action:block withOptions:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionCurveEaseInOut completionBlock:completion]
- // }
- //
- //
- // + (void)rotationViewX:(UIView *)view withDegree:(CGFloat)degree withDuration:(NSTimeInterval)duration
- // {
- // NSString *path = @"transform.rotation.x"
- // [CUCFQuickUIUitil animationView:view withAnimationPath:path toValue:CUCFDegreeToRadiusValue(degree) withDuration:duration]
- // }
- //
- // + (void)rotationViewY:(UIView *)view withDegree:(CGFloat)degree withDuration:(NSTimeInterval)duration
- // {
- // NSString *path = @"transform.rotation.y"
- // [CUCFQuickUIUitil animationView:view withAnimationPath:path toValue:CUCFDegreeToRadiusValue(degree) withDuration:duration]
- // }
- //
- // + (void)rotationViewZ:(UIView *)view withDegree:(CGFloat)degree withDuration:(NSTimeInterval)duration
- // {
- // NSString *path = @"transform.rotation.z"
- // [CUCFQuickUIUitil animationView:view withAnimationPath:path toValue:CUCFDegreeToRadiusValue(degree) withDuration:duration]
- // }
- //
- // + (void)translationViewX:(UIView *)view withOriginX:(CGFloat)originX withDuration:(NSTimeInterval)duration
- // {
- // NSString *path = @"transform.translation.x"
- // [CUCFQuickUIUitil animationView:view withAnimationPath:path toValue:@(originX) withDuration:duration]
- // }
- //
- // + (void)translationViewY:(UIView *)view withOriginY:(CGFloat)originY withDuration:(NSTimeInterval)duration
- // {
- // NSString *path = @"transform.translation.y"
- // [CUCFQuickUIUitil animationView:view withAnimationPath:path toValue:@(originY) withDuration:duration]
- // }
- //
- // + (void)translationViewZ:(UIView *)view withOriginZ:(CGFloat)originZ withDuration:(NSTimeInterval)duration
- // {
- // NSString *path = @"transform.translation.z"
- // [CUCFQuickUIUitil animationView:view withAnimationPath:path toValue:@(originZ) withDuration:duration]
- // }
- //
- // + (void)scaleViewX:(UIView *)view withScaleSize:(CGFloat)size withDuration:(NSTimeInterval)duration
- // {
- // NSString *path = @"transform.scale.x"
- // [CUCFQuickUIUitil animationView:view withAnimationPath:path toValue:@(size) withDuration:duration]
- // }
- //
- // + (void)scaleViewY:(UIView *)view withScaleSize:(CGFloat)size withDuration:(NSTimeInterval)duration
- // {
- // NSString *path = @"transform.scale.y"
- // [CUCFQuickUIUitil animationView:view withAnimationPath:path toValue:@(size) withDuration:duration]
- // }
- //
- // + (void)scaleViewZ:(UIView *)view withScaleSize:(CGFloat)size withDuration:(NSTimeInterval)duration
- // {
- // NSString *path = @"transform.scale.z"
- // [CUCFQuickUIUitil animationView:view withAnimationPath:path toValue:@(size) withDuration:duration]
- // }
- //
- // + (void)animationView:(UIView *)view withAnimationPath:(NSString *)path toValue:(NSValue *)value withDuration:(NSTimeInterval)duration
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- // CABasicAnimation* basicAnimation = [CABasicAnimation animationWithKeyPath:path]
- // basicAnimation.toValue = value
- // basicAnimation.duration = duration
- // basicAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
- // [view.layer addAnimation:basicAnimation forKey:[NSString stringWithFormat:@"cucfAnimation_%@_%lu_%lu_%f",path,(unsigned long)[view hash],(unsigned long)[value hash],duration]]
- // }
- //
- // + (void)view3DRotateX:(UIView *)view withDegree:(CGFloat)degree
- // {
- // [CUCFQuickUIUitil view3DRotate:view x:1 y:0 z:0 withDegree:CUCFDegreeToRadius(degree)]
- // }
- //
- // + (void)view3DRotateY:(UIView *)view withDegree:(CGFloat)degree
- // {
- // [CUCFQuickUIUitil view3DRotate:view x:0 y:1 z:0 withDegree:CUCFDegreeToRadius(degree)]
- // }
- //
- // + (void)view3DRotateZ:(UIView *)view withDegree:(CGFloat)degree
- // {
- // [CUCFQuickUIUitil view3DRotate:view x:0 y:0 z:1 withDegree:CUCFDegreeToRadius(degree)]
- // }
- //
- // + (void)view3DRotate:(UIView *)view x:(CGFloat)xState y:(CGFloat)yState z:(CGFloat)zState withDegree:(CGFloat)degree
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- // CUCFAnimationWithDuration(0.35, ^{
- // view.layer.transform = CATransform3DMakeRotation(degree, xState, yState, zState)
- // })
- // }
- //
- // + (void)view3DTranslateX:(UIView *)view withValue:(CGFloat)value
- // {
- // [CUCFQuickUIUitil view3DTranslate:view x:value y:0 z:0]
- // }
- //
- // + (void)view3DTranslateY:(UIView *)view withValue:(CGFloat)value
- // {
- // [CUCFQuickUIUitil view3DTranslate:view x:0 y:value z:0]
- // }
- //
- // + (void)view3DTranslateZ:(UIView *)view withValue:(CGFloat)value
- // {
- // [CUCFQuickUIUitil view3DTranslate:view x:0 y:0 z:value]
- // }
- //
- // + (void)view3DTranslate:(UIView *)view x:(CGFloat)xState y:(CGFloat)yState z:(CGFloat)zState
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- // CUCFAnimationWithDuration(0.35, ^{
- // view.layer.transform = CATransform3DMakeTranslation(xState, yState, zState)
- // })
- // }
- //
- // + (void)view3DScaleX:(UIView *)view withValue:(CGFloat)value
- // {
- // [CUCFQuickUIUitil view3DScale:view x:value y:0 z:0]
- // }
- //
- // + (void)view3DScaleY:(UIView *)view withValue:(CGFloat)value
- // {
- // [CUCFQuickUIUitil view3DScale:view x:0 y:value z:0]
- // }
- //
- // + (void)view3DScaleZ:(UIView *)view withValue:(CGFloat)value
- // {
- // [CUCFQuickUIUitil view3DScale:view x:0 y:0 z:value]
- // }
- //
- // + (void)view3DScale:(UIView *)view x:(CGFloat)xState y:(CGFloat)yState z:(CGFloat)zState
- // {
- // if (CUCFCheckObjectNull(view)) {
- // return
- // }
- // CUCFAnimationWithDuration(0.35, ^{
- // view.layer.transform = CATransform3DMakeScale(xState, yState, zState)
- // })
- // }
- //
- // + (CUCFQuickUIUitil *)shareQuickUIUitil
- // {
- // static CUCFQuickUIUitil *_shareQuickUIInstance = nil
- // static dispatch_once_t onceToken
- // CUCFDispatchOnce(onceToken, ^{
- //
- // if (!_shareQuickUIInstance) {
- // _shareQuickUIInstance = [[self alloc]init]
- // }
- // })
- // return _shareQuickUIInstance
- // }
- //
- // - (void)addRepeatBlockInfo:(NSDictionary *)blockActionInfoDict
- // {
- // [self.repeatActionInfoDict setObject:blockActionInfoDict forKey:[blockActionInfoDict objectForKey:@"uniqueIdentifier"]]
- // }
- //
- // - (void)repeatAction:(NSTimer *)timer
- // {
- // if (self.repeatActionInfoDict.count == 0) {
- // [self.repeatTimer invalidate]
- // self.repeatTimer = nil
- // return
- // }
- // [self.repeatActionInfoDict enumerateKeysAndObjectsUsingBlock:^(NSString *blockIdentifier, NSDictionary *blockInfoDict, BOOL *stop) {
- //
- // dispatch_block_t action = [blockInfoDict objectForKey:@"action"]
- //
- // NSTimeInterval duration = [[blockInfoDict objectForKey:@"repeatDuration"]doubleValue]
- //
- // NSTimeInterval progress = [[blockInfoDict objectForKey:@"progress"]doubleValue]
- //
- // if (progress <= duration) {
- //
- // CUCFAsyncMainQueue(action)
- //
- // progress = progress + timer.timeInterval
- //
- // [blockInfoDict setValue:@(progress) forKey:@"progress"]
- //
- // [self.repeatActionInfoDict setObject:blockInfoDict forKey:blockIdentifier]
- //
- // }else{
- //
- // [self removeBlockInfo:blockIdentifier]
- // }
- //
- // }]
- //
- // }
- //
- // - (void)removeBlockInfo:(NSString *)blockIdentifier
- // {
- // if (CUCFStringIsNull(blockIdentifier)) {
- // return
- // }
- // if (self.repeatActionInfoDict.count == 0) {
- // return
- // }
- // __block NSString *findDestBlockIdentifier = nil
- // [self.repeatActionInfoDict enumerateKeysAndObjectsUsingBlock:^(NSString *blockIdentifier, NSDictionary *blockInfoDict, BOOL *stop) {
- //
- // NSString *blockInfoIdentifier = [blockInfoDict objectForKey:@"uniqueIdentifier"]
- // if ([blockInfoIdentifier isEqualToString:blockIdentifier]) {
- // findDestBlockIdentifier = blockInfoIdentifier
- // *stop = YES
- // }
- // }]
- // [self.repeatActionInfoDict removeObjectForKey:findDestBlockIdentifier]
- // }
- //
- // - (void)startRepeatAction
- // {
- // if (self.repeatActionInfoDict.count > 0) {
- // if (self.repeatTimer) {
- // [self.repeatTimer invalidate]
- // self.repeatTimer = nil
- // }
- // self.repeatTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(repeatAction:) userInfo:nil repeats:YES]
- // }else{
- // if (self.repeatTimer) {
- // [self.repeatTimer invalidate]
- // self.repeatTimer = nil
- // }
- // }
- // }
- //
- // + (NSString *)repeatDoAction:(dispatch_block_t)block
- // {
- // return [CUCFQuickUIUitil repeatDoAction:block withDelay:0.f]
- // }
- //
- // + (NSString *)repeatDoAction:(dispatch_block_t)block withDelay:(NSTimeInterval)delaySecond
- // {
- // return [CUCFQuickUIUitil repeatDoAction:block withDelay:delaySecond withRepeatDuration:0]
- // }
- //
- // + (NSString *)repeatDoAction:(dispatch_block_t)block withRepeatDuration:(NSTimeInterval)duration
- // {
- // return [CUCFQuickUIUitil repeatDoAction:block withDelay:0 withRepeatDuration:duration]
- // }
- //
- // + (NSString *)repeatDoAction:(dispatch_block_t)block withDelay:(NSTimeInterval)delaySecond withRepeatDuration:(NSTimeInterval)duration
- // {
- // if (CUCFCheckObjectNull(block)) {
- // return nil
- // }
- //
- // NSString *blockIdentifier = CUCFStringCurrentTimeStamp
- //
- // CUCFAsyncMainQueueDelay(delaySecond, ^{
- //
- // NSMutableDictionary *blockActionInfo = [NSMutableDictionary dictionary]
- // [blockActionInfo setObject:block forKey:@"action"]
- // [blockActionInfo setObject:blockIdentifier forKey:@"uniqueIdentifier"]
- // [blockActionInfo setObject:@(0) forKey:@"progress"]
- // [blockActionInfo setObject:@(duration) forKey:@"repeatDuration"]
- //
- // [[CUCFQuickUIUitil shareQuickUIUitil]addRepeatBlockInfo:blockActionInfo]
- // [[CUCFQuickUIUitil shareQuickUIUitil]startRepeatAction]
- //
- // })
- //
- // return blockIdentifier
- // }
- //
- // + (void)stopRepeatAction:(NSString *)blockIdentifier
- // {
- // if (CUCFStringIsNull(blockIdentifier)) {
- // return
- // }
- // [[CUCFQuickUIUitil shareQuickUIUitil]removeBlockInfo:blockIdentifier]
- // }
- //
- // + (void)animationViewXCycle:(UIView *)view withXMoveDetal:(CGFloat)moveX withDuration:(NSTimeInterval)duration
- // {
- // CUCFAnimationViewTranslationX(view, moveX, duration)
- // CUCFAnimationViewTranslationX(view, 0, duration)
- // CUCFAnimationViewTranslationX(view, -moveX, duration)
- // CUCFAnimationViewTranslationX(view, 0, duration)
- // }
- //
- // + (void)animationViewYCycle:(UIView *)view withYMoveDetal:(CGFloat)moveY withDuration:(NSTimeInterval)duration
- // {
- // CUCFAnimationViewTranslationY(view, moveY, duration)
- // CUCFAnimationViewTranslationY(view, 0, duration)
- // CUCFAnimationViewTranslationY(view, -moveY, duration)
- // CUCFAnimationViewTranslationY(view, 0, duration)
- // }
- //
- // + (void)animationViewZCycle:(UIView *)view withZMoveDetal:(CGFloat)moveZ withDuration:(NSTimeInterval)duration
- // {
- // CUCFAnimationViewTranslationZ(view, moveZ, duration)
- // CUCFAnimationViewTranslationZ(view, 0, duration)
- // CUCFAnimationViewTranslationZ(view, -moveZ, duration)
- // CUCFAnimationViewTranslationZ(view, 0, duration)
- // }
- //
- // + (void)animationViewRotateXCycle:(UIView *)view withXRotateDetal:(CGFloat)xDegree withDuration:(NSTimeInterval)duration
- // {
- // CUCFAnimationViewRotateX(view, xDegree, duration)
- // CUCFAnimationViewRotateX(view, 0, duration)
- // CUCFAnimationViewRotateX(view, -xDegree, duration)
- // CUCFAnimationViewRotateX(view, 0, duration)
- // }
- //
- // + (void)animationViewRotateYCycle:(UIView *)view withYRotateDetal:(CGFloat)yDegree withDuration:(NSTimeInterval)duration
- // {
- // CUCFAnimationViewRotateY(view, yDegree, duration)
- // CUCFAnimationViewRotateY(view, 0, duration)
- // CUCFAnimationViewRotateY(view, -yDegree, duration)
- // CUCFAnimationViewRotateY(view, 0, duration)
- // }
- //
- // + (void)animationViewRotateZCycle:(UIView *)view withZRotateDetal:(CGFloat)zDegree withDuration:(NSTimeInterval)duration
- // {
- // CUCFAnimationViewRotateZ(view, zDegree, duration)
- // CUCFAnimationViewRotateZ(view, 0, duration)
- // CUCFAnimationViewRotateZ(view, -zDegree, duration)
- // CUCFAnimationViewRotateZ(view, 0, duration)
- // }
- //
- // /* CAAnimation */
- //
- // + (void)animationLayer:(CALayer *)aLayer positionXWithFromValue:(NSValue *)fromValue withToValue:(NSValue *)toValue withRepeatCount:(NSInteger)repeatCount withDuration:(NSTimeInterval)duration
- // {
- // return [CUCFQuickUIUitil animationLayer:aLayer path:@"position.x" withFromValue:fromValue withToValue:toValue withRepeatCount:repeatCount withDuration:duration]
- // }
- //
- // + (void)animationLayer:(CALayer *)aLayer positionYWithFromValue:(NSValue *)fromValue withToValue:(NSValue *)toValue withRepeatCount:(NSInteger)repeatCount withDuration:(NSTimeInterval)duration
- // {
- // return [CUCFQuickUIUitil animationLayer:aLayer path:@"position.y" withFromValue:fromValue withToValue:toValue withRepeatCount:repeatCount withDuration:duration]
- // }
- //
- // + (void)animationLayer:(CALayer *)aLayer positionCenterWithFromValue:(NSValue *)fromValue withToValue:(NSValue *)toValue withRepeatCount:(NSInteger)repeatCount withDuration:(NSTimeInterval)duration
- // {
- // return [CUCFQuickUIUitil animationLayer:aLayer path:@"position" withFromValue:fromValue withToValue:toValue withRepeatCount:repeatCount withDuration:duration]
- // }
- //
- // + (void)animationLayer:(CALayer *)aLayer path:(NSString *)path withFromValue:(NSValue *)fromValue withToValue:(NSValue *)toValue withRepeatCount:(NSInteger)repeatCount withDuration:(NSTimeInterval)duration
- // {
- // if (CUCFCheckObjectNull(aLayer) || CUCFStringIsNull(path) || CUCFCheckKeyValueHasNull(fromValue, toValue)) {
- // return
- // }
- //
- // CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:path]
- // basicAnimation.fromValue = fromValue
- // basicAnimation.toValue = toValue
- // basicAnimation.duration = duration
- // basicAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
- // basicAnimation.beginTime = 0
- // basicAnimation.autoreverses = YES
- // basicAnimation.repeatCount = repeatCount
- //
- // [aLayer addAnimation:basicAnimation forKey:[NSString stringWithFormat:@"cucf_animation_%@",path]]
- // }
- //
- // + (void)animationLayer:(CALayer *)aLayer positionXByValue:(NSValue *)value withRepeatCount:(NSInteger)repeatCount withDuration:(NSTimeInterval)duration
- // {
- // return [CUCFQuickUIUitil animationLayer:aLayer path:@"position.x" ByValue:value withRepeatCount:repeatCount withDuration:duration]
- // }
- //
- // + (void)animationLayer:(CALayer *)aLayer positionYByValue:(NSValue *)value withRepeatCount:(NSInteger)repeatCount withDuration:(NSTimeInterval)duration
- // {
- // return [CUCFQuickUIUitil animationLayer:aLayer path:@"position.y" ByValue:value withRepeatCount:repeatCount withDuration:duration]
- // }
- //
- // + (void)animationLayer:(CALayer *)aLayer positionCenterByValue:(NSValue *)value withRepeatCount:(NSInteger)repeatCount withDuration:(NSTimeInterval)duration
- // {
- // return [CUCFQuickUIUitil animationLayer:aLayer path:@"position" ByValue:value withRepeatCount:repeatCount withDuration:duration]
- // }
- //
- // + (void)animationLayer:(CALayer *)aLayer path:(NSString *)path ByValue:(NSValue *)value withRepeatCount:(NSInteger)repeatCount withDuration:(NSTimeInterval)duration
- // {
- // if (CUCFCheckObjectNull(aLayer) || CUCFStringIsNull(path) || CUCFCheckObjectNull(value)) {
- // return
- // }
- //
- // CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:path]
- // basicAnimation.byValue = value
- // basicAnimation.duration = duration
- // basicAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
- // basicAnimation.beginTime = 0
- // basicAnimation.autoreverses = YES
- // basicAnimation.repeatCount = repeatCount
- //
- // [aLayer addAnimation:basicAnimation forKey:[NSString stringWithFormat:@"cucf_animation_by_%@",path]]
- //
- // }
- //
- // #pragma mark - 获取圆角图片
- //
- // // Returns true if the image has an alpha layer
- // + (BOOL)hasAlpha:(UIImage *)aImage {
- // CGImageAlphaInfo alpha = CGImageGetAlphaInfo(aImage.CGImage)
- // return (alpha == kCGImageAlphaFirst ||
- // alpha == kCGImageAlphaLast ||
- // alpha == kCGImageAlphaPremultipliedFirst ||
- // alpha == kCGImageAlphaPremultipliedLast)
- // }
- //
- // // Returns a copy of the given image, adding an alpha channel if it doesn't already have one
- // + (UIImage *)imageWithAlpha:(UIImage *)aImage {
- // if ([CUCFQuickUIUitil hasAlpha:aImage]) {
- // return aImage
- // }
- //
- // CGFloat scale = MAX(aImage.scale, 1.0f)
- // CGImageRef imageRef = aImage.CGImage
- // size_t width = CGImageGetWidth(imageRef)*scale
- // size_t height = CGImageGetHeight(imageRef)*scale
- //
- // // The bitsPerComponent and bitmapInfo values are hard-coded to prevent an "unsupported parameter combination" error
- // CGContextRef offscreenContext = CGBitmapContextCreate(NULL,
- // width,
- // height,
- // 8,
- // 0,
- // CGImageGetColorSpace(imageRef),
- // kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst)
- //
- // // Draw the image into the context and retrieve the new image, which will now have an alpha layer
- // CGContextDrawImage(offscreenContext, CGRectMake(0, 0, width, height), imageRef)
- // CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(offscreenContext)
- // UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha scale:aImage.scale orientation:UIImageOrientationUp]
- //
- // // Clean up
- // CGContextRelease(offscreenContext)
- // CGImageRelease(imageRefWithAlpha)
- //
- // return imageWithAlpha
- // }
- //
- // // Creates a copy of this image with rounded corners
- // // If borderSize is non-zero, a transparent border of the given size will also be added
- // // Original author: Björn Sållarp. Used with permission. See: http://blog.sallarp.com/iphone-uiimage-round-corners/
- // + (UIImage *)roundedCornerImage:(UIImage *)aImage cornerSize:(NSInteger)cornerSize borderSize:(NSInteger)borderSize {
- // // If the image does not have an alpha layer, add one
- // UIImage *image = [CUCFQuickUIUitil imageWithAlpha:aImage]
- //
- // CGFloat scale = MAX(aImage.scale,1.0f)
- // NSUInteger scaledBorderSize = borderSize * scale
- //
- // // Build a context that's the same dimensions as the new size
- // CGContextRef context = CGBitmapContextCreate(NULL,
- // image.size.width*scale,
- // image.size.height*scale,
- // CGImageGetBitsPerComponent(image.CGImage),
- // 0,
- // CGImageGetColorSpace(image.CGImage),
- // CGImageGetBitmapInfo(image.CGImage))
- //
- // // Create a clipping path with rounded corners
- //
- // CGContextBeginPath(context)
- // [CUCFQuickUIUitil addRoundedRectToPath:CGRectMake(scaledBorderSize, scaledBorderSize, image.size.width*scale - borderSize * 2, image.size.height*scale - borderSize * 2)
- // context:context
- // ovalWidth:cornerSize*scale
- // ovalHeight:cornerSize*scale]
- // CGContextClosePath(context)
- // CGContextClip(context)
- //
- // // Draw the image to the context; the clipping path will make anything outside the rounded rect transparent
- // CGContextDrawImage(context, CGRectMake(0, 0, image.size.width*scale, image.size.height*scale), image.CGImage)
- //
- // // Create a CGImage from the context
- // CGImageRef clippedImage = CGBitmapContextCreateImage(context)
- // CGContextRelease(context)
- //
- // // Create a UIImage from the CGImage
- // UIImage *roundedImage = [UIImage imageWithCGImage:clippedImage scale:aImage.scale orientation:UIImageOrientationUp]
- //
- // CGImageRelease(clippedImage)
- //
- // return roundedImage
- // }
- //
- // #pragma mark -
- // #pragma mark Private helper methods
- //
- // // Adds a rectangular path to the given context and rounds its corners by the given extents
- // // Original author: Björn Sållarp. Used with permission. See: http://blog.sallarp.com/iphone-uiimage-round-corners/
- // + (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight {
- // if (ovalWidth == 0 || ovalHeight == 0) {
- // CGContextAddRect(context, rect)
- // return
- // }
- // CGContextSaveGState(context)
- // CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect))
- // CGContextScaleCTM(context, ovalWidth, ovalHeight)
- // CGFloat fw = CGRectGetWidth(rect) / ovalWidth
- // CGFloat fh = CGRectGetHeight(rect) / ovalHeight
- // CGContextMoveToPoint(context, fw, fh/2)
- // CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1)
- // CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1)
- // CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1)
- // CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1)
- // CGContextClosePath(context)
- // CGContextRestoreGState(context)
- // }
- //
- // + (UIImage *)createRoundCornerImage:(UIImage *)aImage withCornerSize:(NSInteger)cornerSize withBoardSize:(NSInteger)boardSize
- // {
- // if (!aImage) {
- // return nil
- // }
- // return [CUCFQuickUIUitil roundedCornerImage:aImage cornerSize:cornerSize borderSize:boardSize]
- // }
-
- }
- public let SharedQuickUIUtil: QuickUIUtil = QuickUIUtil.share
|