美文网首页
iOS实现点击状态栏自动回到顶部效果详解

iOS实现点击状态栏自动回到顶部效果详解

作者: tinaH | 来源:发表于2017-01-12 12:12 被阅读41次

把这些代码粘贴到你的ViewController就搞定啦

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

UIWindow * coverWindow =[[UIWindow alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20)];

self.coverWindow = coverWindow;

coverWindow.hidden = YES;

coverWindow.backgroundColor = [UIColor whiteColor];

coverWindow.windowLevel = UIWindowLevelAlert;

//添加手势

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(coverWindowClick)];

[self.coverWindow addGestureRecognizer:tap];

});

- (void)coverWindowClick {

[UIView animateWithDuration:0.5 animations:^{

self.tableView.contentOffset =  CGPointMake(0, 0);

}];

}

原文链接 http://www.jianshu.com/p/d48e9eba5e58

相关文章

网友评论

      本文标题:iOS实现点击状态栏自动回到顶部效果详解

      本文链接:https://www.haomeiwen.com/subject/mkgkbttx.html