#define WIDTH UIScreen.mainScreen.bounds.size.width
#define HEIGHT UIScreen.mainScreen.bounds.size.height
#import "ViewController.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UIView *_backView;
}
@end
@implementation ViewController
- (void)dealloc {
}
- (void)viewDidLoad {
[superviewDidLoad];
self.view.backgroundColor = [UIColorredColor];
UIView *backView = [[UIViewalloc] initWithFrame:CGRectMake(0, HEIGHT - 50,WIDTH, HEIGHT +50)];
backView.backgroundColor = [UIColororangeColor];
[self.viewaddSubview:backView];
UIPanGestureRecognizer * panGestureRecognizer = [[UIPanGestureRecognizeralloc] initWithTarget:self action:@selector(doHandlePanAction:)];
[backView addGestureRecognizer:panGestureRecognizer];
_backView = backView;
UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeSystem];
btn.frame =CGRectMake(WIDTH/2-50,0,100, 50);
btn.backgroundColor = [UIColorcyanColor];
[backView addSubview:btn];
UITableView * tableView = [[UITableViewalloc] initWithFrame:CGRectMake(0,50, WIDTH,HEIGHT) style:UITableViewStylePlain];
tableView.delegate =self;
tableView.dataSource =self;
[backView addSubview:tableView];
[tableView addObserver:selfforKeyPath:@"contentOffset"options:NSKeyValueObservingOptionNewcontext:nil];
}
- (void)doHandlePanAction:(UIPanGestureRecognizer *)paramSender{
CGPoint point = [paramSendertranslationInView:self.view];
NSLog(@"X:%f;Y:%f",point.x,point.y);
// paramSender.view.center = CGPointMake(paramSender.view.center.x + point.x, paramSender.view.center.y + point.y);
paramSender.view.center =CGPointMake(paramSender.view.center.x, paramSender.view.center.y + point.y);
[paramSender setTranslation:CGPointMake(0,0) inView:self.view];
if ( paramSender.state ==UIGestureRecognizerStateEnded) {
NSLog(@"%f,%f",_backView.frame.origin.y,HEIGHT/4 *3);
if (_backView.frame.origin.y > HEIGHT/4 *3) {
[selftableViewShow:NO];
}else {
[selftableViewShow:YES];
}
}
}
- (void)tableViewShow:(BOOL)show {
[UIViewanimateWithDuration:0.3animations:^{
_backView.frame =CGRectMake(0, show?-50:HEIGHT-50,WIDTH, HEIGHT);
} completion:^(BOOL finished) {
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return30;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *str =@"cellIde";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:str];
if (!cell) {
cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:str];
}
return cell;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([keyPathisEqualToString:@"contentOffset"]) {
CGPoint offset = [change[NSKeyValueChangeNewKey]CGPointValue];
NSLog(@" ===== offset ====%f",offset.y);
if (offset.y < -20) {
[selftableViewShow:NO];
}
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
iOS 项目中用到的拖拽界面动画
最新推荐文章于 2021-02-06 20:53:21 发布