Sharon's World

Think deeply,work hard.


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签

  • 公益404

控制UIScrollView的减速速度

发表于 Apr 20 2017 | 分类于 iOS |

手指在UIScrollView上滑动后,会再减速一段距离,如果觉得减速之后滑动的距离太远了,可以通过decelerationRate的值来控制减速的距离。

通过系统默认值修改

系统提供以下两个值:
UIScrollViewDecelerationRateNormal :正常减速
UIScrollViewDecelerationRateFast:快速减速
默认情况下UIScrollView使用UIScrollViewDecelerationRateNormal,如果将其改为UIScrollViewDecelerationRateFast,会发现滚动的距离明显降下来了。

self.tableView.decelerationRate = UIScrollViewDecelerationRateFast;

通过自定义值修改

decelerationRate类型为CGFloat,范围是(0.0,1.0)。
上面两个常量的值分别是:
UIScrollViewDecelerationRateNormal :0.998
UIScrollViewDecelerationRateFast:0.99

如果以上值还不能满足需求的话,我们可以将其设为范围内的任意值。比如将其设置为0.1,会发现滑动之后很快就停下来了。

对产品架构的思考

发表于 Jan 24 2017 | 分类于 软件开发 |

从哪些方面去思考产品架构

1. 针对App

  • 如何让业务开发工程师方便安全地调用网络API?然后尽可能保证用户在各种网络环境下都能有良好的体验?
  • 页面如何组织,才能尽可能降低业务方代码的耦合度?尽可能降低业务方开发界面的复杂度,提高他们的效率?
  • 当数据有在本地存取的需求的时候,如何能够保证数据在本地的合理安排?如何尽可能地减小性能消耗?
  • iOS应用有审核周期,如何能够通过不发版本的方式展示新的内容给用户?如何修复紧急bug?
阅读全文 »

《哪些知识会让你变蠢?》摘录

发表于 Aug 8 2016 | 分类于 读书 |

今天在一个微信公众号上看了一篇文章《哪些知识会让你变蠢?》,其中的一些文字多多少少让我构建知识体系这一命题有了更进一步的认识。

阅读全文 »

使用CAShapeLayer实现画虚线

发表于 Jul 9 2016 | 分类于 iOS |
- (void)drawRect:(CGRect)rect {
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:self.bounds];
    [shapeLayer setPosition:CGPointMake(self.frame.size.width / 2.0, self.frame.size.height)];
    [shapeLayer setFillColor:[UIColor clearColor].CGColor];
    //设置虚线颜色
    [shapeLayer setStrokeColor:[UIColor colorWithWhite:226.f/255.f alpha:1].CGColor];
    //设置虚线宽度
    [shapeLayer setLineWidth:self.frame.size.height];
    [shapeLayer setLineJoin:kCALineJoinRound];
    //设置虚线的线宽及间距
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithInt:3], nil]];
    //创建虚线绘制路径
    CGMutablePathRef path = CGPathCreateMutable();
    //设置虚线绘制路径起点
    CGPathMoveToPoint(path, NULL, 0, 0);
    //设置虚线绘制路径终点
    CGPathAddLineToPoint(path, NULL, self.frame.size.width, 0);
    //设置虚线绘制路径
    [shapeLayer setPath:path];
    CGPathRelease(path);
    //添加虚线
    [self.layer addSublayer:shapeLayer];
}

UITableView section header 不固定

发表于 Jul 9 2016 | 分类于 iOS |

iOS系统自带的UITableView,当数据分为多个section的时候,在UITableView滑动的过程中,默认section header是固定在顶部的,滑动到下一个section的时候,下一个section header把上一个section header顶出屏幕外。典型的应用就是通讯录。

默认情况下,UITableView的section header是固定的,如何让section header不固定呢?也就是随着UITableView的滑动而滑动,顶部不是一直都显示section header。方法是设置UITableView 的contentInset。代码如下:

#pragma mark - scrollView代理函数
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // 修改contentSize
    if([scrollView isKindOfClass:[UITableView class]]){// 不固定section
        CGFloat sectionHeaderHeight = pxToCoordinate(TABLECELL_SECTION_HEADER);
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
}

原理:当滑动的值大于section header的高度时,设置其contentInset,达到不显示header的效果,这样就类似于将header给顶出了屏幕;当滑动至小于section header的高度时,恢复contentInset,显示header。

需要注意:因为UITableView 滑动时contentOffset会不断的改变,因此该部分代码需要写到 scrollViewDidScroll 方法中。

About Laying out Subviews

发表于 Apr 11 2016 | 分类于 iOS |

layoutSubviews

官方文档引用:

You should override this method only if the autoresizing and
constraint-based behaviors of the subviews do not offer the behavior
you want.

我的理解是:
在subview的autoresizing和constraint不满足你的要求时,可以重写layoutSubviews。假设一个屏幕从竖屏变为横屏,本来图文单元是图片在上,文字在下面,可能就变为了左右结构;这是无论自动适配还是自动布局都解决不了,就只能重写layoutSubviews函数了。

阅读全文 »

什么时候应该重写viewDidLayoutSubviews?

发表于 Mar 23 2016 | 分类于 iOS |

viewDidLoad

重写viewDidLoad是为了配置任何你没有在XIB或者Storyboard中配置的东西。
当View controller的视图层从XIB或Storyboard被加载到内存中的时候,viewDidLoad也会被调用。
当在loadView方法中代码实现一个view的时候(使用loadVIew的时候,没有必要再使用viewDidLoad)

阅读全文 »

我的2015

发表于 Dec 28 2015 | 分类于 生活记录 |

2015年快要告一段落,这一年平稳中又有进步,很知足。

阅读全文 »
12…4
Sharon Hu

Sharon Hu

sharon's blog

28 日志
7 分类
32 标签
RSS
© 2017 Sharon Hu
由 Hexo 强力驱动
|
主题 — NexT.Gemini