博文

目前显示的是标签为“从老博客搬家而来”的博文

iOS8 Spring Animation

自 iOS 8 开始,Apple 公开了 Spring Animation 的 API,开发者也可以使用简单的代码创建这类动画效果了: + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion 该方法是  UIView  的类方法。 Spring Animation 的 API 和一般动画相比多了两个参数,分别是  usingSpringWithDamping  和  initialSpringVelocity 。 dumping ratio usingSpringWithDamping  的范围为  0.0f  到  1.0f  ,数值越小「弹簧」的振动效果越明显。下图演示了在  initialSpringVelocity  为  0.0f  的情况下,  usingSpringWithDamping  分别取  0.2f  ,  0.5f  和  1.0f 的情况。 initial velocity initialSpringVelocity  则表示初始的速度,数值越大一开始移动越快。下图演示了在  usingSpringWithDamping  为  1.0f  时,  initia...

搭建NavigationController+TabBar的通用步骤。

这种架构的应用会经常使用,特此记录。 1、新建项目,删除Deployment Info下的Main Interface里的“Main” 2、新建UITabBarController或导入第三方Tabbar。 3、如果是第三方,则根据第三方方法进行设置;若为自己建立的TabbarController,则在TabBar的.m内进行设置。 1)编写添加所有子视图控制器方法: -(void) viewdidload{ [super viewdidload]; [self setUpAllChildViewController]; } - (void)setUpAllChildViewController{    // 1.添加第一个控制器     UIViewController *oneVC = [[UIViewController alloc]init];     [self setUpOneChildViewController:oneVC image:[UIImage imageNamed:@"tab_home_icon"] title:@"111"];    // 2.添加第2个控制器     UITableViewController *twoVC = [[UITableViewController alloc]init];     [self setUpOneChildViewController:twoVC image:[UIImage imageNamed:@"js"] title:@"222"];    // 3.添加第3个控制器     UIViewController *threeVC = [[UIViewController alloc]init];     [self setUpOneChildViewController:threeVC image:[UIImage imageNamed:@"qw"] title:@"333"];    // 4.添加第4个控制器     UITableViewCon...

UIScrollView的一个坑。

当更改UIScrollView的contentsize时,会重置其contentoffset!

UITextField的代理执行顺序分析

当没有任何textfield获取交点时,直接执行textFieldShouldBeginEditing 当从一个textfield跳到另一个textfield时,先执行textFieldShouldBeginEditing,再执行textFieldShouldEndEditing

获取UITableViewCell中UITextField的值方法总结

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {     NSInteger row = [indexPath row];           static NSString  *CellIdentifier = @"CellIdentifier";           UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];           if (cell == nil) {         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];         cell.selectionStyle = UITableViewCellSelectionStyleNone;     }           cell.textLabel.text = [_passwordArray objectAtIndex:row];           CGRect textFieldRect = CGRectMake(0.0, 0.0f, 215.0f, 31.0f);     UITextField *theTextField = [[UITextField alloc] initWithFrame:textFieldRect];    ...

TableviewCell去除 点按效果

最好要在cell里设置,cell.selectionStyle = UITableViewCellSelectionStyleNone;

有关TableView的reload过程分析。

在tableview的区域reload过程中: [tableview reloadRowsAtIndexPaths:_selectedIndexes withRowAnimation:UITableViewRowAnimationAutomatic];(假设此方法在didsele里面)那么 首先执行的是 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 会将需要显示的cell高度全部遍历一遍 然后 执行 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 会  仅  将需要刷新的cell数据刷新一下 然后 会再执行一遍 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 仅  返回刚才cellForRowAtIndexPath里面刷新过的cell。 至此刷新完毕。

去掉TableView后面最后一个Cell下面的横线

static void setLastCellSeperatorToLeft(UITableViewCell* cell) {     if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {         [cell setSeparatorInset:UIEdgeInsetsZero];     }         if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {         [cell setLayoutMargins:UIEdgeInsetsZero];     }         if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){         [cell setPreservesSuperviewLayoutMargins:NO];     } }

UIView clipsTobounds

view1添加view2到其中,如果view2大于view1,或者view2的坐标不在view1的范围内,view2是盖着view1的,意思就是超出的部份也会画出来 UIView有一个属性,clipsTobounds 默认情况下是NO, 如果,我们想要view2把超出的那部份隐藏起来的话,就得改变它的父视图也就view1的clipsTobounds属性值。 view1.clipsTobounds = YES;

自定义navigationbar左边的按钮

先放这里,以后复制就好~ viewdidload: self.navigationItem.leftBarButtonItem = [self leftBarButtonItem]; 其它函数: - (UIBarButtonItem *)leftBarButtonItem{        UIButton *left = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 11, 20)];     [left setBackgroundImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];     [left addTarget:self action:@selector(popViewCon) forControlEvents:UIControlEventTouchUpInside];     [left setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];     [left setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];        UIBarButtonItem *item = [self barItemWithCustomView:left];     return item; } - (UIBarButtonItem *)barItemWithCustomView:(id)custom{     return [[UIBarButtonItem alloc]initWithCustomView:(UIView *)custom]; } -(void)popViewCon {     [self.navigationController popViewContro...

去除TableView多余的线

tableview.tablefooterview = [[UIView alloc]init]; 或 [tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];

Dictionary里面有关"Null"的判断方法。

if ((NSNull*)dic[@"email"]!=[NSNull null]) { }

蒲公英发布后APP无法安装

Application requires iPhone environment这个一定要为YES才可以安装。

CocoaPods慢的解决方法

pod install --no-repo-update

手势滑动返回功能

现在使用默认模板创建的 iOS  App都支持 手势返回 功能,如果导航栏的返回按钮是自定义的那么则会失效,也可以参考 这里 手动设置无效。 if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; } 如果是因为自定义导航按钮而导致 手势返回 失效,那么可以在NavigationController的viewDidLoad函数中添加如下代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. __weak typeof (self) weakSelf = self; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestureRecognizer.delegate = weakSelf; } } 这样写了以后就可以通过手势滑动返回上一层了,但是如果在push过程中触发手势滑动返回,会导致导航栏崩溃(从日志中可以看出)。针对这个问题,我们需要在pop过程禁用手势滑动返回功能: - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { // fix 'nested pop animation can result in corrupted navigation bar' if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestur...

iOS AttributeString~

在iOS中或者Mac OS X中怎样才能将一个字符串绘制到屏幕上呢?        简单来说,是通过控件来完成的,而这些控件都封装在UIKit框架中(对于Mac OS X是AppKit框架),在UIKit中常用来在屏幕上显示字符串的控件有3个:         UILabel         UITextField         UITextView        然而这些控件本身对文本的展现方式很单一,通常仅仅能够控制字体样式、大小、颜色、加粗、斜体等等,而对于行距控制,字距控制,段落控制等高级功能却无能为力。        此时不免要提起一个非常强大的文本排版框架CoreText.framework。        CoreText框架是基于 iOS 3.2+ 和 OSX 10.5+ 的一种能够对文本格式和文本布局进行精细控制的文本引擎。它良好的结合了 UIKit 和 Core Graphics/Quartz:        UIKit 的 UILabel 允许你通过在 IB 中简单的拖曳添加文本,但你不能改变文本的颜色和其中的单词。        Core Graphics/Quartz几乎允许你做任何系统允许的事情,但你需要为每个字形计算位置,并画在屏幕上。        CoreText正结合了这两者!你自己可以完全控制位置、布局、类似文本大小和颜色这样的属性,CoreText将帮你完善其它的东西——类似文本换行、字体呈现等等。        然而,CoreText.framework本身非常庞大,学习成本较高,使用起来也不是很方便,所以一般不是特殊需要,很少会有人去使用它。        随着iOS6 API的发布,文字显示的API越来越完善,其中一个重要的更新是在UITextFi...