1、滾動隱藏或者顯示導航欄
先聲明兩個屬性
@property(nonatomic)CGFloatbeginContentY;//開始滑動的位置
@property(nonatomic)CGFloatendContentY;//結(jié)束滑動的位置
//當開始滾動視圖時,執(zhí)行該方法。一次有效滑動(開始滑動,滑動一小段距離,只要手指不松開,只算一次滑動),只執(zhí)行一次。
- (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView{
//獲取開始位置
self.beginContentY= scrollView.contentOffset.y;
}
//滑動scrollView,并且手指離開時執(zhí)行。一次有效滑動,只執(zhí)行一次。
//當pagingEnabled屬性為YES時,不調(diào)用,該方法
- (void)scrollViewWillEndDragging:(UIScrollView*)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inoutCGPoint*)targetContentOffset{
//獲取結(jié)束位置
self.endContentY= scrollView.contentOffset.y;
if(self.endContentY-self.beginContentY>10)
{
[UIViewanimateWithDuration:0.25animations:^{
CGRectrect =self.navigationController.navigationBar.frame;
rect.origin.y= -44;
self.navigationController.navigationBar.frame= rect;
}];
}elseif(self.endContentY-self.beginContentY< -10){
[UIViewanimateWithDuration:0.25animations:^{
CGRectrect =self.navigationController.navigationBar.frame;
rect.origin.y=0;
self.navigationController.navigationBar.frame= rect;
}completion:^(BOOLfinished) {
}];
}
}
如果效果不好,可以適當修改tableView的位置。self.mainTableView.transform=CGAffineTransformMakeTranslation(0,44);
2、如果想在字符串里打出%
只要“%%”即可。
打出“1%”
NSString *str = [NSString stringWithFormatter:@"%d%%",1];
3、自定義導航欄左側(cè)按鈕,導致右滑返回上一層界面的手勢失效的問題。
viewController.navigationController.interactivePopGestureRecognizer.delegate= (id)self;
viewController.navigationController.interactivePopGestureRecognizer.enabled=YES;
viewController是推出的那個界面。
如果第一個界面右滑卡死,則添加
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;//一行代碼解決問題,注意要寫在viewDidAppear方法里
}
4、float的精度解決
將NSNumber轉(zhuǎn)化為CGFloat時,精度失真。
NSString *decimalNumberMutiplyWithString(NSString *multiplierValue,NSString *multiplicandValue)
{
NSDecimalNumber?*multiplierNumber?=?[NSDecimalNumber?decimalNumberWithString:multiplierValue];
NSDecimalNumber?*multiplicandNumber?=?[NSDecimalNumber?decimalNumberWithString:multiplicandValue];
NSDecimalNumber?*product?=?[multiplicandNumber?decimalNumberByMultiplyingBy:multiplierNumber];
return?[product?stringValue];
}
NSLog(@"%@",decimalNumberMutiplyWithString([NSString?stringWithFormat:@"%f",a],?[NSString?stringWithFormat:@"%d",b]));?//輸出結(jié)果?999999.99
通過計算每一位的數(shù)字,再進行string展示。
- (NSString *)convertStringFromFloatNum:(NSNumber *)floatNum
{
NSNumberFormatter?*numberFormatter?=?[[NSNumberFormatter?alloc]?init];
[numberFormatter?setPositiveFormat:@"0.00"];
NSString?*tempFloatStr?=?[numberFormatter?stringFromNumber:[NSNumber?numberWithDouble:([floatNum?floatValue]?*?100)]];??//?yuan?to?fen
NSInteger?tempInt?=?[tempFloatStr?integerValue];
NSInteger?result?=?tempInt?%?100;
if?(0?==?result)?{
NSString?*str?=?[NSString?stringWithFormat:@"%zd",?tempInt/100];
return?str;
}
result?=?tempInt?%?10;
if?(0?==?result)?{
NSString?*str?=?[NSString?stringWithFormat:@"%zd.%zd",?tempInt/100,?(tempInt?%?100)/10];
return?str;
}
NSString?*str?=?[NSString?stringWithFormat:@"%zd.%zd%zd",?tempInt/100,?(tempInt?%?100)/10,?(tempInt?%?100)];
return?str;
}
5、解決tableView里被鍵盤擋住超簡單的辦法,簡直不可思議?。?/p>
//處理鍵盤遮擋問題
UITableViewController*tvc = [[UITableViewControlleralloc]initWithStyle:UITableViewStylePlain];
[selfaddChildViewController:tvc];
_pointInfoTableView= tvc.tableView;
6、使用AsyncDisplayKit
使用FaceBook出品的AsyncDisplayKit來寫復雜的界面。能夠獲得異步繪制,預先加載等諸多好處。不過,需要一定的學習成本,前段時間看了下網(wǎng)易新聞的安裝包,就使用了AsyncDisplayKit
大多數(shù)性能要求較高的界面就是圖文混排,比如微博Feed,微信朋友圈等界面。建議使用成熟的圖文混排引擎,因為這些引擎一般支持異步繪制,并且做了大量優(yōu)化。推薦兩個