当从左到右单击btw时,我添加视图,并希望从右到左移除此视图。
下面是我从左到右添加视图时的代码
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];
}];为了从右向左移除这个视图,我尝试的是:
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];
}];我想从右到左移除视图.Any帮助如何进一步进行?
发布于 2015-07-01 06:07:58
您必须将您的子视图移出superview的框架,因此将您的子视图的x坐标设置为其自身宽度的负值。这将导致您的视图从右移动到左移。
[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];
}];发布于 2015-07-01 06:34:32
您可以这样删除它:
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*/}];发布于 2018-04-05 14:07:03
Swift 3和4版本:
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应该是类变量(属性)
https://stackoverflow.com/questions/31153633
复制相似问题