【发布时间】:2026-02-10 01:00:01
【问题描述】:
GIF 显示了问题。 下面的代码显示了我如何将视图添加到超级视图中并从超级视图底部弹出。此代码在 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];
}];
}
【问题讨论】:
-
不要更新动画块中的约束常量。
-
@Desdenova 已删除及其工作发现,但现在如何在 iOS 10 中对其进行动画处理?
-
将
layoutIfNeeded位保留在块中。只是不要在其中设置常量。 -
@Desdenova 不工作
标签: objective-c xcode animation uiview ios10