把這些代碼粘貼到你的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;
//添加手勢(shì)
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.itdecent.cn/p/d48e9eba5e58