假设主视图的高度为h。
我有两个uivivew高度h / 2(让我们称他们为上下视图)。
我想添加向上和向下滑动手势,以便
- 如果我向上滑动
如果向下视图和向上视图高度是h / 2并向上滑动,则必须使向下视图高度为h,并且必须使向上视图高度为0。
如果向上视图高度为h且向下视图高度为0,则必须使向下视图和向上视图高度为h / 2
我想要制作动画,以便高度增加和减少必须平滑可见。
答案 0 :(得分:1)
答案 1 :(得分:1)
这是我的回答
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initialization];
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self viewDesign];
}
-(void)initialization{
viewUpHeight.constant=self.view.frame.size.height/2;
viewDownHeight.constant=self.view.frame.size.height/2;
}
-(void)viewDesign{
UISwipeGestureRecognizer *swipeUpGestureRecognizer =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUp:)];
swipeUpGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUpGestureRecognizer];
UISwipeGestureRecognizer *swipeDownGestureRecognizer =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDown:)];
swipeDownGestureRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeDownGestureRecognizer];
}
-(void)swipeUp:(UISwipeGestureRecognizer *)swipeGes{
if(viewUp.frame.size.height==self.view.frame.size.height) {
}else {
CGRect basketTopFrame = self.viewUp.frame;
basketTopFrame.origin.y = -basketTopFrame.size.height;
// basketTopFrame.size.height=0;
CGRect basketBottomFrame = self.viewDown.frame;
basketBottomFrame.size.height=self.view.frame.size.height;
basketBottomFrame.origin.y =0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.viewUp.frame = basketTopFrame;
self.viewDown.frame = basketBottomFrame;
[UIView commitAnimations];
}
}
-(void)swipeDown:(UISwipeGestureRecognizer *)swipeGes{
if(viewDown.frame.size.height==self.view.frame.size.height){
CGRect basketTopFrame = self.viewUp.frame;
basketTopFrame.origin.y =0;
CGRect basketBottomFrame = self.viewDown.frame;
basketBottomFrame.origin.y =self.view.frame.size.height/2;
basketBottomFrame.size.height=self.view.frame.size.height/2;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.viewUp.frame = basketTopFrame;
self.viewDown.frame = basketBottomFrame;
[UIView commitAnimations];
}
}