I suggest you implement viewWillTransitionToSize
in your ViewController
var landscapeViewFrame = CGRect()
var landscapeTableViewFrame = CGRect()
var portraitViewFrame = CGRect()
var portraitTableViewFrame = CGRect()
override func viewDidLoad() {
super.viewDidLoad()
landscapeViewFrame = CGRectMake(0, 0, view.frame.width / 2, view.frame.height)
landscapeTableViewFrame = CGRectMake(view.frame.width, 0, view.frame.width / 2, self.view.frame.height);
portraitViewFrame = view.bounds
portraitTableViewFrame = CGRectMake(0,0,0,0);
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
let isPortrait = (size.height > size.width);
yourView.frame = isPortrait ? portraitViewFrame : landscapeViewFrame
yourTableView.frame = isPortrait ? portraitTableViewFrame : landscapeTableViewFrame
yourTableView.hidden = isPortrait
}
viewWillTransitionToSize
notifies your viewController that the view frame is going to change. The UIViewControllerTransitionCoordinator
contains information about the animation, such as the duration / if animated at all.
Update now in swift.
Basic idea: calculate the designated frames before. On device rotation change, the viewWillTransitionToSize
is called and the frames for your views can be set. As mentioned before, you'll probably need animations to make everything look smooth