GIF显示了这个问题。 下面的代码显示了我如何将视图添加到superview并从superview的底部调出。此代码在iOS 9中运行良好,而在iOS 10中运行良好。
上滑动画的动画不合适。它是从右侧出来,而不是直接从底部形成角度。
请帮我解决这个问题。
+ (ControlsView *)addArticleControlsToView:(UIView *)view bellowSubview:(UIView *)subview{
ControlsView *articleControls = [[[NSBundle mainBundle] loadNibNamed:@"ControlsView" owner:self options:nil]firstObject];
[view insertSubview:articleControls belowSubview:subview];
NSDictionary *viewsDict = @{@"currentView":articleControls};
[articleControls setTranslatesAutoresizingMaskIntoConstraints:NO];
NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"H:|-0-[currentView]-0-|"] options:0 metrics:@{} views:viewsDict];
NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[currentView(189)]-0-|" options:0 metrics:@{} views:viewsDict];
[view addConstraints:horizontalConstraints];
[view addConstraints:verticalConstraints];
[articleControls setBackgroundColor:[UIColor clearColor]];
articleControls.viewBottomConstraint.constant = -189;
[articleControls layoutIfNeeded];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:articleControls action:@selector(slideSheetDown)];
[articleControls addGestureRecognizer:tapGesture];
return articleControls;
}
- (void)slideSheetUp {
[UIView animateWithDuration:0.5 animations:^{
self.viewBottomConstraint.constant = 0;
self.scrollViewBottomConstraint.constant = 189;
[self setBackgroundColor:[UIColor clearColor]];
[self.scrollView.superview layoutIfNeeded];
[self layoutIfNeeded];
}];
}
答案 0 :(得分:0)
只需使用此代码
- (void)slideSheetUp {
self.viewBottomConstraint.constant = 0;
self.scrollViewBottomConstraint.constant = 189;
[self setBackgroundColor:[UIColor clearColor]];
[UIView animateWithDuration:0.5 animations:^{
[self.scrollView.superview layoutIfNeeded];
[self layoutIfNeeded];
}];
}
希望它对你有用。 ;)
快乐的编码!!
答案 1 :(得分:0)
适合我。
-(void)hideShowTimerButton:(BOOL)show{
[UIView animateWithDuration:0.3 animations:^{
CGRect yourViewFrame = yourView.frame;
if(show){
timeContainerViewFrame.origin.y = self.view.frame.size.height;
}else{
timeContainerViewFrame.origin.y = self.view.frame.size.height - yourViewFrame.size.height;
}
yourView.frame = yourViewFrame;
} completion:^(BOOL finished) {
}];
}
答案 2 :(得分:0)
请重新安排你的代码如下,它没有影响我的视图动画太多,并解决了我的问题。谢谢你们。
- (void)slideSheetUp {
self.viewBottomConstraint.constant = 0;
[self setBackgroundColor:[UIColor clearColor]];
[UIView animateWithDuration:0.5 animations:^{
[self layoutIfNeeded];
} completion:^(BOOL finished) {
self.scrollViewBottomConstraint.constant = 189;
[self.scrollView.superview layoutIfNeeded];
}];
}