当向上滑动被检测到时,我的视图控制器中有一些视图会上移,然后当向下滑动被检测到时会下移。我曾经通过调整y坐标原点来强制视图移动。现在,我已经使用IB将约束应用于我的视图,但是我不确定如何最好地移动视图,以便它们在iPhone 5、6和6+上以正确的位置结束。
目前,我正在做类似这样的事情:
[self.view layoutIfNeeded];
self.panFrameVerticalConstraint.constant = self.panFrameVerticalConstraint.constant +338;
[UIView animateWithDuration:5
animations:^{
[self.view layoutIfNeeded];
}];
更好的做法是使用比例来改变常数吗?因此,对于以上约束条件,是否最好这样做:
self.panFrameVerticalConstraint.constant = self.panFrameVerticalConstraint.constant + (self.panView.frame.size.height/1.680);
//self.panView.frame.size.height = 568
//(568/1.680) = 338
IBOutlet
NSLayoutConstraint
属性,并将其连接到我想要在界面构建器中调整的约束。然后,当我需要将我的视图向上移动时,我像这样更改了我的常量self.panFrameVerticalConstraint.constant = -(self.panedView.frame.size.height/1.68);
。在更改常量之前,我调用了layoutIfNeeded
。更改常量后,我调用了animateWithDuration
并在块中再次调用了layoutIfNeeded
,就像下面的回答一样。 - BrosefviewDidLoad
中,您需要添加一个UISwipeGestureRecognizer
和当检测到滑动时调用的方法。UISwipeGestureRecognizer * swipeUpRec = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleUpSwipe:)];
然后将手势识别器添加到应该检测滑动的任何框架[self.someView addGestureRecognizer:swipeUpRec];
。 - Brosef