I have a couple views in my view controller that move up when an up swipe is detected then down when a down swipe is detected. I was forcing the views to move by adjusting the y origin using CGRectOffset. I've now applied constraints to my views with IB and I'm not sure whats the best way to move the views so that they end up in the right position on the iphone 5, 6, and 6+.
Currently I'm doing something like this:
[self.view layoutIfNeeded];
self.panFrameVerticalConstraint.constant = self.panFrameVerticalConstraint.constant +338;
[UIView animateWithDuration:5
animations:^{
[self.view layoutIfNeeded];
}];
Is it better to change the constants using ratios? So for the constraint above, instead of using 338, would it be better to do this:
self.panFrameVerticalConstraint.constant = self.panFrameVerticalConstraint.constant + (self.panView.frame.size.height/1.680);
//self.panView.frame.size.height = 568
//(568/1.680) = 338



IBOutletNSLayoutConstraintproperty and connected it to the constraint I wanted to adjust in interface builder. Then when I needed to move my view up, i changed my constant like thisself.panFrameVerticalConstraint.constant = -(self.panedView.frame.size.height/1.68);. I calledlayoutIfNeededbefore changing the constant. After changing the constant I calledanimateWithDurationand calledlayoutIfNeededagain in the block just like the answer below. - BrosefviewDidLoadyou need to add aUISwipeGestureRecognizerand the method that gets called when a swipe is detected.UISwipeGestureRecognizer * swipeUpRec = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleUpSwipe:)];Then add the gesture recognizer to whatever frame is suppose to detect the swipe[self.someView addGestureRecognizer:swipeUpRec];- Brosef