1、數字的各類特殊格式:git
NSNumber *num1 = [NSNumber numberWithDouble:1234567.8369];測試
// 四捨五入的整數動畫
NSString *numberNoStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterNoStyle];orm
// 小數形式three
NSString *numberDecimalStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterDecimalStyle];ip
// 貨幣形式 -- 本地化ci
NSString *numberCurrencyStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterCurrencyStyle];rem
// 百分數形式animation
NSString *numberPercentStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterPercentStyle];string
// 科學計數
NSString *numberScientificStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterScientificStyle];
// 朗讀形式 -- 本地化
NSString *numberSpellOutStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterSpellOutStyle];
// 序數形式 -- 本地化
NSString *numberOrdinalStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterOrdinalStyle];
// 貨幣形式 ISO -- 本地化
NSString *numberCurrencyISOStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterCurrencyISOCodeStyle];
// CGAffineTransform 位移、旋轉、縮放
// 貨幣形式 -- 本地化
NSString *numberCurrencyPluralStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterCurrencyPluralStyle];
// 會計計數 -- 本地化
NSString *numberCurrencyAccountingStyleStr = [NSNumberFormatter localizedStringFromNumber:num1 numberStyle:NSNumberFormatterCurrencyAccountingStyle];
NSLog(@"No Style = %@",numberNoStyleStr); // No Style = 1234568
NSLog(@"Decimal Style = %@",numberDecimalStyleStr); // Decimal Style = 1,234,567.837
NSLog(@"Currency Style = %@",numberCurrencyStyleStr); // Currency Style = $1,234,567.84
NSLog(@"Percent Style = %@",numberPercentStyleStr); // Percent Style = 123,456,784%
NSLog(@"Scientific Style = %@",numberScientificStyleStr); // Scientific Style = 1.2345678369E6
// Spell Out Style = one million two hundred thirty-four thousand five hundred sixty-seven point eight three six nine
NSLog(@"Spell Out Style = %@",numberSpellOutStyleStr);
NSLog(@"Ordinal Style = %@",numberOrdinalStyleStr); // Ordinal Style = 1,234,568th
NSLog(@"Currency ISO Style = %@",numberCurrencyISOStyleStr); // Currency ISO Style = USD1,234,567.84
NSLog(@"Currency plural Style = %@",numberCurrencyPluralStyleStr); // Currency plural Style = 1,234,567.84 US dollars
NSLog(@"Currency accounting Style = %@",numberCurrencyAccountingStyleStr); // Currency accounting Style = $1,234,567.84
// ==================== 定製 ====================
NSNumberFormatter *numberFormatter = [NSNumberFormatter new];
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
// 格式寬度
numberFormatter.formatWidth = 15;
// 填充符
numberFormatter.paddingCharacter = @"?";
// 填充位置
numberFormatter.paddingPosition = kCFNumberFormatterPadBeforeSuffix;
numberFormatter.positiveSuffix = @"元";
NSLog(@"%@",[numberFormatter numberFromString:@"10000000元"]); // 10000000
// 縮放因子,你能夠將一個數縮放指定比例,而後給其添加後綴,如傳入一個3000,你但願表示爲3千,就要用到這個屬性
// 防止影響後面的測試,故注掉
// numberFormatter.multiplier = @1000;
// NSLog(@"%@千",[numberFormatter numberFromString:@"1000"]); // 1千
// numberFormatter.multiplier = @0.001;
// numberFormatter.positiveSuffix = @"千";
// NSLog(@"%@",[numberFormatter stringFromNumber:@10000]); // 10千
// 機制不明確,負號,正號
// numberFormatter.negativeFormat = @"^";
// numberFormatter.positiveFormat = @"~0";
// 貌似沒什麼用
numberFormatter.allowsFloats = NO;
numberFormatter.alwaysShowsDecimalSeparator = NO;
numberFormatter.maximum = @1000;
numberFormatter.minimum = @100;
// 小數點樣式
numberFormatter.decimalSeparator = @".";
// 零的樣式
numberFormatter.zeroSymbol = @"-";
// 前綴和後綴
numberFormatter.positivePrefix = @"!";
numberFormatter.positiveSuffix = @"元";
numberFormatter.negativePrefix = @"@";
numberFormatter.negativeSuffix = @"虧";
// 指定符號,與咱們在前面類方法中說明的一致
NSLog(@"貨幣代碼%@",numberFormatter.currencyCode); // 貨幣代碼USD
NSLog(@"貨幣符號%@",numberFormatter.currencySymbol); // 貨幣符號$
NSLog(@"國際貨幣符號%@",numberFormatter.internationalCurrencySymbol); // 國際貨幣符號USD
NSLog(@"百分比符號%@",numberFormatter.percentSymbol); // 百分比符號%
NSLog(@"千分號符號%@",numberFormatter.perMillSymbol); // 千分號符號‰
NSLog(@"減號符號%@",numberFormatter.minusSign); // 減號符號-
NSLog(@"加號符號%@",numberFormatter.plusSign); // 加號符號+
NSLog(@"指數符號%@",numberFormatter.exponentSymbol); // 指數符號E
// 整數最多位數
numberFormatter.maximumIntegerDigits = 10;
// 整數最少位數
numberFormatter.minimumIntegerDigits = 2;
// 小數位最多位數
numberFormatter.maximumFractionDigits = 3;
// 小數位最少位數
numberFormatter.minimumFractionDigits = 1;
// 數字分割的尺寸
numberFormatter.groupingSize = 4;
// 除了groupingSize決定的尺寸外,其餘數字位分割的尺寸
numberFormatter.secondaryGroupingSize = 2;
// 最大有效數字個數
numberFormatter.maximumSignificantDigits = 12;
// 最少有效數字個數
numberFormatter.minimumSignificantDigits = 3;
NSLog(@"正數%@,負數%@",[numberFormatter stringFromNumber:@(+12135230.2346)],[numberFormatter stringFromNumber:@(-12135231.2346)]); // 正數!12,13,5230.2346元,負數@12,13,5231.2346虧
NSLog(@"零 = %@",[numberFormatter stringFromNumber:@(0)]); // 零 = -
// 舍入值,好比以10爲進位值,那麼156就進位爲160,154進位爲150
numberFormatter.roundingIncrement = @10;
// 舍入方式
numberFormatter.roundingMode = kCFNumberFormatterRoundHalfUp;
NSLog(@"%@",[numberFormatter stringFromNumber:@123456.7890]); // !12,3460元
2、視圖的抖動動畫
// 二、抖動動畫
CGPoint currentPosition = self.imgView.layer.position;
//移動的兩個終點位置
CGPoint beginPosition = CGPointMake(currentPosition.x + 10, currentPosition.y);
CGPoint endPosition = CGPointMake(currentPosition.x - 10, currentPosition.y);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
//設置開始位置
[animation setFromValue:[NSValue valueWithCGPoint:beginPosition]];
//設置結束位置
[animation setToValue:[NSValue valueWithCGPoint:endPosition]];
// [animation setAutoreverses:YES];
animation.duration = 0.03;
animation.repeatCount = 3;
[self.imgView.layer addAnimation:animation forKey:@""];