ios 開發(fā)中常用的方法(計(jì)算文本地淀,正則表達(dá)式失球,圖片壓縮,視圖變化等)

#pragma mark - 計(jì)算label可以顯示多少個字?jǐn)?shù)

+ (NSInteger)numberOfStringInUpper:(UILabel *)label stringToSeperate:(NSString *)str{? ? CGRect container = label.frame;? ? CGSize detailSize;? ? for (int i = 0; i < [str length]; i ++) {? ? ? ? NSString *textStr = [str substringToIndex:i+1];? ? ? ? NSDictionary *attribute = @{NSFontAttributeName: label.font};? ? ? ? detailSize = [textStr boundingRectWithSize:CGSizeMake(container.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading? attributes:attribute context:nil].size;? ? ? ? ? ? ? ? if (detailSize.height > container.size.height) {? ? ? ? ? ? return i;? ? ? ? }? ? }? ? container.size.height = detailSize.height;? ? [label setFrame:container]; //調(diào)整高度? ? return [str length];}

#pragma mark - 計(jì)算文本寬高 -

- (CGSize)getContentStr:(NSString *)text widthSize:(CGFloat)width heightSize:(CGFloat)height FontOfSize:(UIFont *)fontSize

{

CGSize requiredSize;

CGRect rect = [text boundingRectWithSize:CGSizeMake(width, height)

options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesFontLeading

attributes:@{NSFontAttributeName:fontSize}

context:nil];

requiredSize = rect.size;

return requiredSize;

}

#pragma mark - 當(dāng)前視圖大小變化

+ (CAAnimation *)starTimer:(CGFloat)duration original:(CGFloat)original midNumerical:(CGFloat)midNumerical endNumerical:(CGFloat)endNumerical

{

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];

animation.values = @[[NSNumber numberWithFloat:original], [NSNumber numberWithFloat:midNumerical], [NSNumber numberWithFloat:endNumerical]];//大小變化倍數(shù)

animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

/*

速度控制函數(shù)(CAMediaTimingFunction)

kCAMediaTimingFunctionLinear(線性):勻速帮毁,給你一個相對靜態(tài)的感覺

kCAMediaTimingFunctionEaseIn(漸進(jìn)):動畫緩慢進(jìn)入实苞,然后加速離開

kCAMediaTimingFunctionEaseOut(漸出):動畫全速進(jìn)入,然后減速的到達(dá)目的地

kCAMediaTimingFunctionEaseInEaseOut(漸進(jìn)漸出):動畫緩慢的進(jìn)入烈疚,中間加速黔牵,然后減速的到達(dá)目的地。 這個是默認(rèn)的動畫行為爷肝。

*/

animation.duration = duration;//動畫執(zhí)行的時間

animation.repeatCount = HUGE_VALF;//播放次數(shù)

animation.autoreverses = NO;// 當(dāng)你設(shè)定這個屬性為 YES 時,在它到達(dá)目的地之后,動畫的返回到開始的值,代替了直接跳轉(zhuǎn)到 開始的值猾浦。

animation.removedOnCompletion = NO;//這個屬性默認(rèn)為 YES,那意味著,在指定的時間段完成后,動畫就自動的從層上移除了陆错。這個一般不用。假如你想要再次用這個動畫時,你需要設(shè)定這個屬性為 NO跃巡。這樣的話,下次你在通過-set 方法設(shè)定動畫的屬 性時,它將再次使用你的動畫,而非默認(rèn)的動畫

animation.fillMode=kCAFillModeForwards;

/*

fillMode的作用就是決定當(dāng)前對象過了非active時間段的行為. 比如動畫開始之前,動畫結(jié)束之后危号。如果是一個動畫CAAnimation,則需要將其removedOnCompletion設(shè)置為NO,要不然fillMode不起作用.

kCAFillModeRemoved 這個是默認(rèn)值,也就是說當(dāng)動畫開始前和動畫結(jié)束后,動畫對layer都沒有影響,動畫結(jié)束后,layer會恢復(fù)到之前的狀態(tài)

kCAFillModeForwards 當(dāng)動畫結(jié)束后,layer會一直保持著動畫最后的狀態(tài)

kCAFillModeBackwards 這個和kCAFillModeForwards是相對的,就是在動畫開始前,你只要將動畫加入了一個layer,layer便立即進(jìn)入動畫的初始狀態(tài)并等待動畫開始.你可以這樣設(shè)定測試代碼,將一個動畫加入一個layer的時候延遲5秒執(zhí)行.然后就會發(fā)現(xiàn)在動畫沒有開始的時候,只要動畫被加入了layer,layer便處于動畫初始狀態(tài)

kCAFillModeBoth 理解了上面兩個,這個就很好理解了,這個其實(shí)就是上面兩個的合成.動畫加入后開始之前,layer便處于動畫初始狀態(tài),動畫結(jié)束后layer保持動畫最后的狀態(tài).

*/

return animation;

}

#pragma mark - 當(dāng)前視圖透明度變化

+ (CAAnimation *)fadeInOutAnimation:(CGFloat)duration fromValue:(CGFloat)fromValue toValue:(CGFloat)toValue

{

//通過keypath創(chuàng)建路徑

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"opacity"];

animation.duration = duration;

animation.repeatCount = HUGE_VALF;

animation.fromValue = [NSNumber numberWithFloat:fromValue];

animation.toValue = [NSNumber numberWithFloat:toValue];

animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

animation.autoreverses = NO;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

return animation;

}

#pragma mark - 截取全屏

- (UIImage *)imageFromView:(UIView*)theView

{

UIGraphicsBeginImageContext(theView.frame.size);

CGContextRef context = UIGraphicsGetCurrentContext();

[theView.layer renderInContext:context];

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return theImage;

}

#pragma mark - 數(shù)組排序

- (NSArray *)getSortingArray:(NSArray *)array{

// 返回一個排好序的數(shù)組钮莲,原來數(shù)組的元素順序不會改變

// 指定元素的比較方法:compare:

NSArray *array2 = [array sortedArrayUsingSelector:@selector(compare:)];

return array2;

}

#pragma mark - 點(diǎn)贊效果 大小變化

- (void)imageViewAnimationLayer:(UIView *)view{

CAKeyframeAnimation *k = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];

k.values = @[@(0.1),@(1.0),@(1.2)];

k.keyTimes = @[@(0.0),@(0.5),@(0.8),@(1.0)];

k.calculationMode = kCAAnimationLinear;

[view.layer addAnimation:k forKey:@"trans"];

}

#pragma mark - 獲取當(dāng)前時間

+ (NSString *)getCurrentTime{

//現(xiàn)在時間

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSString *currentTime = [NSString stringWithFormat:@"%@",[formatter stringFromDate:[NSDate date]]];

formatter = nil;

return currentTime;

}

#pragma mark 圖片壓縮

+ (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize withImage:(UIImage*)selectedImage

{

//方法2

CGFloat scaxy=1.0;

const int maxW = targetSize.width, maxH = targetSize.height;

if (selectedImage.size.height>maxH && selectedImage.size.width >maxW)

{

CGFloat scax = maxH/selectedImage.size.width;

CGFloat scay = maxW/selectedImage.size.height;

if (scax > scay)

{

scaxy = scay;

}

else

{

scaxy = scax;

}

}

UIGraphicsBeginImageContext(CGSizeMake(selectedImage.size.width * scaxy, selectedImage.size.height *scaxy));

// Tell the old image to draw in this new context, with the desired// new size

[selectedImage drawInRect:CGRectMake(0,0,selectedImage.size.width * scaxy, selectedImage.size.height *scaxy)];

UIImage? ? *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return newImage;

}

#pragma mark - 隨機(jī)顏色

+(UIColor *)randomColor:(CGFloat)alpha

{

CGFloat red = arc4random_uniform(253);

CGFloat green = arc4random_uniform(254);

CGFloat blue = arc4random_uniform(255);

//? ? CGFloat red = arc4random() % 256 ;//(CGFloat)random()/(CGFloat)RAND_MAX;

//? ? CGFloat green =arc4random() % 256 ; //(CGFloat)random()/(CGFloat)RAND_MAX;

//? ? CGFloat blue = arc4random() % 256 ;//(CGFloat)random()/(CGFloat)RAND_MAX;

return [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha];

}

// 正則判斷電話號碼地址格式,固話

+(BOOL)isTelePhone:(NSString *)telePhoneNum

{

/**

* 手機(jī)號碼

* 移動:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188

* 聯(lián)通:130,131,132,152,155,156,185,186

* 電信:133,1349,153,180,189

*/

NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";

/**

10? ? ? ? * 中國移動:China Mobile

11? ? ? ? * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188

12? ? ? ? */

NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";

/**

15? ? ? ? * 中國聯(lián)通:China Unicom

16? ? ? ? * 130,131,132,152,155,156,185,186

17? ? ? ? */

NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";

/**

20? ? ? ? * 中國電信:China Telecom

21? ? ? ? * 133,1349,153,180,189

22? ? ? ? */

NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";

/**

25? ? ? ? * 大陸地區(qū)固話及小靈通

26? ? ? ? * 區(qū)號:010,020,021,022,023,024,025,027,028,029

27? ? ? ? * 號碼:七位或八位

28? ? ? ? */

//? ? NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";

NSString * PHS = @"^((\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1})|(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))$";

//? ? NSString * PHS = @"^(\\b0[1-2]\\d-\\d{8}(-\\d{1,4})?\\b)|(\\b0\\d{3}-\\d{7,8}(-\\d{1,4})?\\b)$";

//? ? NSString * PHS = @"^(0?1[358]\\d{9})|((0(10|2[1-3]|[3-9]\\d{2}))?[1-9]\\d{6,7})$";

NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];

NSPredicate *regextestphs = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", PHS];

NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];

NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];

NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];

if (([regextestmobile evaluateWithObject:telePhoneNum] == YES)

||([regextestphs evaluateWithObject:telePhoneNum] == YES)

|| ([regextestcm evaluateWithObject:telePhoneNum] == YES)

|| ([regextestct evaluateWithObject:telePhoneNum] == YES)

|| ([regextestcu evaluateWithObject:telePhoneNum] == YES))

{

return YES;

}

else

{

return NO;

}

}

//判斷是否中文

+ (BOOL)isChinese:(NSString *)string{

NSString *miaoNumRegex =@"^[\u4e00-\u9fa5]{0,}$";

NSPredicate *passTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",miaoNumRegex];

return [passTest evaluateWithObject:string];

}

#pragma mark - 計(jì)算文本寬高 -

//+(CGSize)getSize:(NSString *)str widthSize:(CGFloat)width FontOfSize:(CGFloat)fontSize

//{

//? ? CGSize requiredSize;

//? ? if ([str respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {

//? ? ? ? CGRect rect = [str boundingRectWithSize:(CGSize){width, MAXFLOAT}

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? options:NSStringDrawingUsesLineFragmentOrigin

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]}

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? context:nil];

//? ? ? ? requiredSize = rect.size;

//

//? ? } else {

//

//? ? ? ? requiredSize = [str sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:(CGSize){width, MAXFLOAT} lineBreakMode:NSLineBreakByWordWrapping];

//? ? }

//

//? ? return requiredSize;

//}

//+(CGSize)getSize:(NSString *)str widthSize:(CGFloat)width FontOfBSize:(CGFloat)fontSize

//{

//? ? CGSize requiredSize;

//? ? if ([str respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {

//? ? ? ? CGRect rect = [str boundingRectWithSize:(CGSize){width, MAXFLOAT}

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? options:NSStringDrawingUsesLineFragmentOrigin

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:fontSize]}

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? context:nil];

//? ? ? ? requiredSize = rect.size;

//

//? ? } else {

//

//? ? ? ? requiredSize = [str sizeWithFont:[UIFont boldSystemFontOfSize:fontSize] constrainedToSize:(CGSize){width, MAXFLOAT} lineBreakMode:NSLineBreakByWordWrapping];

//? ? }

//

//? ? return requiredSize;

//}

//身份證號

+ (BOOL)validateIdentityCard: (NSString *)identityCard

{

BOOL flag;

if (identityCard.length <= 0) {

flag = NO;

return flag;

}

NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";

NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];

return [identityCardPredicate evaluateWithObject:identityCard];

}

// 判斷郵箱是否正確

+ (BOOL)isValidateEmail:(NSString *)Email

{

NSString *emailCheck = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";

NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailCheck];

return [emailTest evaluateWithObject:Email];

}

//判斷字母數(shù)字

+ (BOOL)IsNumber:(NSString *)number

{

//是否字母數(shù)字

NSString *miaoNumRegex =@"^[a-zA-Z0-9_]+$";

NSPredicate *passTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",miaoNumRegex];

return [passTest evaluateWithObject:number];

}

//#pragma mark 圖片壓縮

//+ (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize withImage:(UIImage*)selectedImage

//{

//? ? //方法1

////? ? CGFloat scaxy=1.0;

////? ? CGSize imageSize = selectedImage.size;

////? ? CGFloat targetWidth = targetSize.width;

////? ? CGFloat targetHeight = targetSize.height;

////

////? ? if (CGSizeEqualToSize(imageSize, targetSize) == NO)

////? ? {

////? ? ? ? CGFloat scax = targetWidth / imageSize.width;

////? ? ? ? CGFloat scay =? targetHeight / imageSize.height;

////? ? ? ? if (scax > scay)

////? ? ? ? {

////? ? ? ? ? ? scaxy = scay;

////? ? ? ? }

////? ? ? ? else

////? ? ? ? {

////? ? ? ? ? ? scaxy = scax;

////? ? ? ? }

////? ? }

////

////? ? CGFloat scaledWidth = selectedImage.size.width * scaxy;

////? ? CGFloat scaledHeight = selectedImage.size.height *scaxy;

////

//////? ? UIGraphicsBeginImageContext(CGSizeMake(selectedImage.size.width * scaxy, selectedImage.size.height *scaxy));

////? ? UIGraphicsBeginImageContext(CGSizeMake(scaledWidth, scaledHeight));

////? ? // Tell the old image to draw in this new context, with the desired// new size

//////? ? [selectedImage drawInRect:CGRectMake(0,0,selectedImage.size.width * scaxy, selectedImage.size.height *scaxy)];

////

////? ? CGRect thumbnailRect = CGRectZero;

////? ? thumbnailRect.origin = CGPointMake(0.0, 0.0);

////? ? thumbnailRect.size.width = scaledWidth;

////? ? thumbnailRect.size.height = scaledHeight;

////

////? ? CGContextRef context = UIGraphicsGetCurrentContext();

////? ? CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);

////? ? UIRectFill(CGRectMake(0, 0, targetWidth, targetHeight));//clear background

////

////? ? [selectedImage drawInRect:thumbnailRect];

////

////? ? UIImage? ? *newImage = UIGraphicsGetImageFromCurrentImageContext();

////? ? UIGraphicsEndImageContext();

//

//? ? //方法2

//? ? ? ? CGFloat scaxy=1.0;

//? ? ? ? const int maxW = targetSize.width, maxH = targetSize.height;

//? ? ? ? if (selectedImage.size.height>maxH && selectedImage.size.width >maxW)

//? ? ? ? {

//? ? ? ? ? ? CGFloat scax = maxH/selectedImage.size.width;

//? ? ? ? ? ? CGFloat scay = maxW/selectedImage.size.height;

//? ? ? ? ? ? if (scax > scay)

//? ? ? ? ? ? {

//? ? ? ? ? ? ? ? scaxy = scay;

//? ? ? ? ? ? }

//? ? ? ? ? ? else

//? ? ? ? ? ? {

//? ? ? ? ? ? ? ? scaxy = scax;

//? ? ? ? ? ? }

//? ? ? ? }

//? ? ? ? UIGraphicsBeginImageContext(CGSizeMake(selectedImage.size.width * scaxy, selectedImage.size.height *scaxy));

//? ? ? ? // Tell the old image to draw in this new context, with the desired// new size

//? ? ? ? [selectedImage drawInRect:CGRectMake(0,0,selectedImage.size.width * scaxy, selectedImage.size.height *scaxy)];

//? ? ? ? UIImage? ? *newImage = UIGraphicsGetImageFromCurrentImageContext();

//? ? ? ? UIGraphicsEndImageContext();

//

////? 方法3

////? ? //? ? UIImage *selectedImage = self;

////? ? UIImage *newImage = nil;

////? ? CGSize imageSize = selectedImage.size;

////? ? CGFloat width = imageSize.width;

////? ? CGFloat height = imageSize.height;

////? ? CGFloat targetWidth = targetSize.width;

////? ? CGFloat targetHeight = targetSize.height;

////? ? CGFloat scaleFactor = 0.0;

////? ? CGFloat scaledWidth = targetWidth;

////? ? CGFloat scaledHeight = targetHeight;

//////? ? CGPoint thumbnailPoint = CGPointMake(0.0,0.0);

////

////? ? if (CGSizeEqualToSize(imageSize, targetSize) == NO)

////? ? {

////? ? ? ? CGFloat widthFactor = targetWidth / width;

////? ? ? ? CGFloat heightFactor = targetHeight / height;

////

////? ? ? ? if (widthFactor > heightFactor)

////? ? ? ? ? ? scaleFactor = widthFactor; // scale to fit height

////? ? ? ? else

////? ? ? ? ? ? scaleFactor = heightFactor; // scale to fit width

////? ? ? ? scaledWidth? = width * scaleFactor;

////? ? ? ? scaledHeight = height * scaleFactor;

////

////? ? ? ? // center the image 裁剪中間

//////? ? ? ? if (widthFactor > heightFactor)

//////? ? ? ? {

//////? ? ? ? ? ? thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;

//////? ? ? ? }

//////? ? ? ? else

//////? ? ? ? ? ? if (widthFactor < heightFactor)

//////? ? ? ? ? ? {

//////? ? ? ? ? ? ? ? thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;

//////? ? ? ? ? ? }

////? ? }

////

//////? ? UIGraphicsBeginImageContext(targetSize); // this will crop

////? ? UIGraphicsBeginImageContext(CGSizeMake(scaledWidth, scaledHeight)); // this will crop

////

////? ? CGRect thumbnailRect = CGRectZero;

//////? ? thumbnailRect.origin = thumbnailPoint;

////? ? thumbnailRect.size.width? = scaledWidth;

////? ? thumbnailRect.size.height = scaledHeight;

////

////? ? [selectedImage drawInRect:thumbnailRect];

////

////? ? newImage = UIGraphicsGetImageFromCurrentImageContext();

////? ? if(newImage == nil)

////? ? ? ? NSLog(@"could not scale image");

////

////? ? //pop the context to get back to the default

////? ? UIGraphicsEndImageContext();

//? ? return newImage;

//}

//

//+(UIImage *)scaleAndRotateImage:(UIImage *)image resolution:(int)kMaxResolution{

//? ? CGImageRef imgRef = image.CGImage;

//? ? CGFloat width = CGImageGetWidth(imgRef);

//? ? CGFloat height = CGImageGetHeight(imgRef);

//

//? ? CGAffineTransform transform = CGAffineTransformIdentity;

//? ? CGRect bounds = CGRectMake(0, 0, width, height);

//? ? if (width > kMaxResolution || height > kMaxResolution) {

//? ? ? ? CGFloat ratio = width/height;

//? ? ? ? if (ratio > 1) {

//? ? ? ? ? ? bounds.size.width = kMaxResolution;

//? ? ? ? ? ? bounds.size.height = bounds.size.width / ratio;

//? ? ? ? } else {

//? ? ? ? ? ? bounds.size.height = kMaxResolution;

//? ? ? ? ? ? bounds.size.width = bounds.size.height * ratio;

//? ? ? ? }

//? ? }

//

//? ? CGFloat scaleRatio = bounds.size.width / width;

//? ? CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));

//? ? CGFloat boundHeight;

//

//? ? UIImageOrientation orient = image.imageOrientation;

//? ? switch(orient) {

//? ? ? ? case UIImageOrientationUp:

//? ? ? ? ? ? transform = CGAffineTransformIdentity;

//? ? ? ? ? ? break;

//? ? ? ? case UIImageOrientationUpMirrored:

//? ? ? ? ? ? transform = CGAffineTransformMakeTranslation(imageSize.width, 0.0);

//? ? ? ? ? ? transform = CGAffineTransformScale(transform, -1.0, 1.0);

//? ? ? ? ? ? break;

//? ? ? ? case UIImageOrientationDown:

//? ? ? ? ? ? transform = CGAffineTransformMakeTranslation(imageSize.width, imageSize.height);

//? ? ? ? ? ? transform = CGAffineTransformRotate(transform, M_PI);

//? ? ? ? ? ? break;

//? ? ? ? case UIImageOrientationDownMirrored:

//? ? ? ? ? ? transform = CGAffineTransformMakeTranslation(0.0, imageSize.height);

//? ? ? ? ? ? transform = CGAffineTransformScale(transform, 1.0, -1.0);

//? ? ? ? ? ? break;

//? ? ? ? case UIImageOrientationLeftMirrored:

//? ? ? ? ? ? boundHeight = bounds.size.height;

//? ? ? ? ? ? bounds.size.height = bounds.size.width;

//? ? ? ? ? ? bounds.size.width = boundHeight;

//? ? ? ? ? ? transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width);

//? ? ? ? ? ? transform = CGAffineTransformScale(transform, -1.0, 1.0);

//? ? ? ? ? ? transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);

//? ? ? ? ? ? break;

//? ? ? ? case UIImageOrientationLeft:

//? ? ? ? ? ? boundHeight = bounds.size.height;

//? ? ? ? ? ? bounds.size.height = bounds.size.width;

//? ? ? ? ? ? bounds.size.width = boundHeight;

//? ? ? ? ? ? transform = CGAffineTransformMakeTranslation(0.0, imageSize.width);

//? ? ? ? ? ? transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);

//? ? ? ? ? ? break;

//? ? ? ? case UIImageOrientationRightMirrored:

//? ? ? ? ? ? boundHeight = bounds.size.height;

//? ? ? ? ? ? bounds.size.height = bounds.size.width;

//? ? ? ? ? ? bounds.size.width = boundHeight;

//? ? ? ? ? ? transform = CGAffineTransformMakeScale(-1.0, 1.0);

//? ? ? ? ? ? transform = CGAffineTransformRotate(transform, M_PI / 2.0);

//? ? ? ? ? ? break;

//? ? ? ? case UIImageOrientationRight:

//? ? ? ? ? ? boundHeight = bounds.size.height;

//? ? ? ? ? ? bounds.size.height = bounds.size.width;

//? ? ? ? ? ? bounds.size.width = boundHeight;

//? ? ? ? ? ? transform = CGAffineTransformMakeTranslation(imageSize.height, 0.0);

//? ? ? ? ? ? transform = CGAffineTransformRotate(transform, M_PI / 2.0);

//? ? ? ? ? ? break;

//? ? ? ? default:

//? ? ? ? ? ? [NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];

//? ? }

//

//? ? UIGraphicsBeginImageContext(CGSizeMake(floorf(bounds.size.width), floorf(bounds.size.height)));

//? ? CGContextRef context = UIGraphicsGetCurrentContext();

//? ? if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {

//? ? ? ? CGContextScaleCTM(context, -scaleRatio, scaleRatio);

//? ? ? ? CGContextTranslateCTM(context, -height, 0);

//? ? } else {

//? ? ? ? CGContextScaleCTM(context, scaleRatio, -scaleRatio);

//? ? ? ? CGContextTranslateCTM(context, 0, -height);

//? ? }

//? ? CGContextConcatCTM(context, transform);

//

//? ? CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, floorf(width), floorf(height)), imgRef);

//? ? UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();

//? ? UIGraphicsEndImageContext();

//? ? return imageCopy;

//}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末乔妈,一起剝皮案震驚了整個濱河市庐舟,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌兔朦,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,378評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件磨确,死亡現(xiàn)場離奇詭異沽甥,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)乏奥,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,356評論 2 382
  • 文/潘曉璐 我一進(jìn)店門摆舟,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人邓了,你說我怎么就攤上這事恨诱。” “怎么了骗炉?”我有些...
    開封第一講書人閱讀 152,702評論 0 342
  • 文/不壞的土叔 我叫張陵照宝,是天一觀的道長。 經(jīng)常有香客問我句葵,道長厕鹃,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,259評論 1 279
  • 正文 為了忘掉前任乍丈,我火速辦了婚禮剂碴,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘轻专。我一直安慰自己忆矛,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,263評論 5 371
  • 文/花漫 我一把揭開白布铭若。 她就那樣靜靜地躺著洪碳,像睡著了一般。 火紅的嫁衣襯著肌膚如雪叼屠。 梳的紋絲不亂的頭發(fā)上瞳腌,一...
    開封第一講書人閱讀 49,036評論 1 285
  • 那天,我揣著相機(jī)與錄音镜雨,去河邊找鬼嫂侍。 笑死,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的挑宠。 我是一名探鬼主播菲盾,決...
    沈念sama閱讀 38,349評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼各淀!你這毒婦竟也來了懒鉴?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,979評論 0 259
  • 序言:老撾萬榮一對情侶失蹤碎浇,失蹤者是張志新(化名)和其女友劉穎临谱,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體奴璃,經(jīng)...
    沈念sama閱讀 43,469評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡悉默,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,938評論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了苟穆。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片抄课。...
    茶點(diǎn)故事閱讀 38,059評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖雳旅,靈堂內(nèi)的尸體忽然破棺而出跟磨,到底是詐尸還是另有隱情,我是刑警寧澤岭辣,帶...
    沈念sama閱讀 33,703評論 4 323
  • 正文 年R本政府宣布吱晒,位于F島的核電站,受9級特大地震影響沦童,放射性物質(zhì)發(fā)生泄漏仑濒。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,257評論 3 307
  • 文/蒙蒙 一偷遗、第九天 我趴在偏房一處隱蔽的房頂上張望墩瞳。 院中可真熱鬧,春花似錦氏豌、人聲如沸喉酌。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,262評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽泪电。三九已至,卻和暖如春纪铺,著一層夾襖步出監(jiān)牢的瞬間相速,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評論 1 262
  • 我被黑心中介騙來泰國打工鲜锚, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留突诬,地道東北人苫拍。 一個月前我還...
    沈念sama閱讀 45,501評論 2 354
  • 正文 我出身青樓,卻偏偏與公主長得像旺隙,于是被迫代替她去往敵國和親绒极。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,792評論 2 345

推薦閱讀更多精彩內(nèi)容