1、滚动隐藏或者显示导航栏
先声明两个属性
@property(nonatomic)CGFloatbeginContentY;//开始滑动的位置
@property(nonatomic)CGFloatendContentY;//结束滑动的位置
//当开始滚动视图时,执行该方法。一次有效滑动(开始滑动,滑动一小段距离,只要手指不松开,只算一次滑动),只执行一次。
- (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView{
//获取开始位置
self.beginContentY= scrollView.contentOffset.y;
}
//滑动scrollView,并且手指离开时执行。一次有效滑动,只执行一次。
//当pagingEnabled属性为YES时,不调用,该方法
- (void)scrollViewWillEndDragging:(UIScrollView*)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inoutCGPoint*)targetContentOffset{
//获取结束位置
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、自定义导航栏左侧按钮,导致右滑返回上一层界面的手势失效的问题。
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转化为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])); //输出结果 999999.99
通过计算每一位的数字,再进行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里被键盘挡住超简单的办法,简直不可思议!!
//处理键盘遮挡问题
UITableViewController*tvc = [[UITableViewControlleralloc]initWithStyle:UITableViewStylePlain];
[selfaddChildViewController:tvc];
_pointInfoTableView= tvc.tableView;
6、使用AsyncDisplayKit
使用FaceBook出品的AsyncDisplayKit来写复杂的界面。能够获得异步绘制,预先加载等诸多好处。不过,需要一定的学习成本,前段时间看了下网易新闻的安装包,就使用了AsyncDisplayKit
大多数性能要求较高的界面就是图文混排,比如微博Feed,微信朋友圈等界面。建议使用成熟的图文混排引擎,因为这些引擎一般支持异步绘制,并且做了大量优化。推荐两个
网友评论