下面是動(dòng)畫(huà)效果
話不多說(shuō)卧秘,直接上代碼
視圖的創(chuàng)建
//UITableView頂部的ImageView
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, V_Width, V_height/3)];
self.imageView.image = [UIImage imageNamed:@"3"];
//設(shè)置imageView的填充模式
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
self.imageView.userInteractionEnabled = YES;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(createAllImageView)];
[self.imageView addGestureRecognizer:tap];
//UITableView
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, V_Width, V_height) style:UITableViewStylePlain];
//設(shè)置tableView的內(nèi)邊距
self.tableView.contentInset = UIEdgeInsetsMake(V_height/3, 0, 0, 0);
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
[self.view addSubview:self.imageView];
拖動(dòng)TableView時(shí)的事件
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGPoint point = scrollView.contentOffset;
//下拉圖片放大
if (point.y < -V_height/3 && point.y >= -V_height/3-60) {
CGRect rect = self.imageView.frame;
rect.origin.y = 0;
rect.size.height = -point.y;
self.imageView.frame = rect;
}
//上拉圖片跟隨移動(dòng)
if (point.y > -V_height/3) {
CGRect rect = self.imageView.frame;
rect.origin.y = -point.y - V_height/3;
self.imageView.frame = rect;
}
//下拉到一定程度嚎研,創(chuàng)建新的View
if (point.y <= -V_height/3-60) {
[self createAllImageView];
}
}
創(chuàng)建新的視圖
/**
* 在Window上創(chuàng)建新的View
*/
- (void)createAllImageView{
//V_Width 屏幕寬的宏定義
//V_height 屏幕高的宏定義
//判斷如果已經(jīng)創(chuàng)建_allView,則不在創(chuàng)建
if (_allView) {
return;
}
//Window上的View
_allView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, V_Width, V_height/3)];
_allView.backgroundColor = [UIColor blackColor];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeAllImageView:)];
[_allView addGestureRecognizer:tap];
//新視圖上的ImageView
_likeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, V_Width, V_height/3)];
_likeImageView.image = [UIImage imageNamed:@"3"];
[_allView addSubview:_likeImageView];
//在Window上添加視圖
[[UIApplication sharedApplication].keyWindow addSubview:_allView];
CGRect rect1 = _allView.frame;
rect1.size.height = V_height;
CGRect rect2 = _likeImageView.frame;
rect2.origin.y = (V_height - V_height/3)/2;
//動(dòng)畫(huà)顯示
[UIView animateWithDuration:0.8 animations:^{
_allView.frame = rect1;
_likeImageView.frame = rect2;
}];
}
Window上視圖銷毀
/**
* 移除Window上的View
*
*/
- (void)removeAllImageView:(UITapGestureRecognizer *)tap{
CGRect rect1 = _allView.frame;
rect1.size.height = V_height/3;
CGRect rect2 = _likeImageView.frame;
rect2.origin.y = 0;
//動(dòng)畫(huà)顯示
[UIView animateWithDuration:0.5 animations:^{
_allView.frame = rect1;
_likeImageView.frame = rect2;
_allView.alpha = 0;
} completion:^(BOOL finished) {
[_likeImageView removeFromSuperview];
[_allView removeFromSuperview];
_allView = nil;
}];
}
tableView的一些代理事件這里就不在詳細(xì)的寫(xiě)了墨叛,歡迎大家指正