牛叉的demoiOS开发你需要知道的iOS开发

iOS支付宝首页效果-仿

2017-10-26  本文已影响298人  泰好笑勒

新做的项目,UI指着支付宝首页,咱们就做这个效果!因为之前也被指着说做Instagram的相册选择效果,就满口答应了。本着无百度不扣钉的思想,也发现有人写了这个。哈哈,可以复制啦。然而,看了代码之后,还是决定自己写了。

盗图1(侵删).jpeg 盗图2(侵删).jpeg

此实现仅使用一个UITableview。顶部View是加在tableview上的。向上滑动的时候,不用任何处理,顶部View就会上滑。向下滑动的时候,实现ScollView的代理即可。额,太简单了~~,没写就完了。只能上代码凑字数了。

- (void)viewDidLoad {
   [super viewDidLoad];
   _contentInsetTop = 100;

  _topView = [[UIView alloc] initWithFrame:CGRectMake(0, -_contentInsetTop, SDScreenWidth, _contentInsetTop)];
  _topView.backgroundColor = [UIColor redColor];

  UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  tableView.dataSource = self;
  tableView.delegate   = self;
  tableView.contentInset = UIEdgeInsetsMake(_contentInsetTop, 0, 0, 0);
  tableView.scrollIndicatorInsets = tableView.contentInset;
  [self.view addSubview:tableView];
  [tableView addSubview:_topView];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat offsetY = scrollView.contentOffset.y;
    if (offsetY < -_contentInsetTop) {
        _topView.frame = CGRectMake(0, offsetY, SDScreenWidth, _contentInsetTop);
    }
}
上一篇 下一篇

猜你喜欢

热点阅读