Reputation: 476
I adding view when btw is clicked from left to right and want to remove this view from right to left.
Below is my code while adding view from left to right
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
bundle: nil];
leftMenu = (LeftMenuViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"menuController"];
leftMenu.view.frame = CGRectMake(-320, 0, 320-50, self.view.frame.size.height);
[self addChildViewController:leftMenu];
[self.view addSubview:leftMenu.view];
[UIView animateWithDuration:0.3 animations:^{
leftMenu.view.frame = CGRectMake(0, 0, 320-50, self.view.frame.size.height);
hoverView.hidden = NO;
} completion:^(BOOL finished) {
[leftMenu didMoveToParentViewController:self];
}];
For removing this view from right to left what i have tried is:
self.view.frame = CGRectMake(320-50, 0, self.view.frame.size.width, self.view.frame.size.height);
[self willMoveToParentViewController:nil];
[UIView animateWithDuration:0.3 animations:^{
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
[self removeFromParentViewController];
[self.view removeFromSuperview];
}];
I want to remove view from right to left .Any help how to proceed further?
Upvotes: 1
Views: 1380
Reputation: 126
Swift 3 and 4 version:
leftMenu.didMove(toParentViewController: nil)
UIView.animate(withDuration: 0.3,
animations: {
self.leftMenu.view.frame = CGRect(x: -self.view.frame.width, y: 0, width: self.view.frame.width, height: self.view.frame.height)
},
completion: { finished in
self.leftMenu.view.removeFromSuperview()
self.leftMenu.removeFromParentViewController()
})
P.S. leftMenu should be class variable (property)
Upvotes: 0
Reputation: 9346
You can remove it like this:
CGRect napkinBottomFrame = Yourview.frame;
napkinBottomFrame.origin.x = 0;
[UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut animations:^{ Yourview.frame = napkinBottomFrame; } completion:^(BOOL finished){/*done*/}];
Upvotes: 0
Reputation: 2413
You must move your subview out of frame of superview, so set x-coordinate of your subview to negative value of it's own width. This will cause your view move from right to left out of view.
[self willMoveToParentViewController:nil];
[UIView animateWithDuration:0.3 animations:^{
self.view.frame = CGRectMake(-self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
[self removeFromParentViewController];
[self.view removeFromSuperview];
}];
Upvotes: 2