GIF顯示此問題。 下面的代碼顯示我如何將視圖添加到超級視圖並從超級視圖底部調出。此代碼在iOS 9中運行良好,而在iOS 10中運行良好。UIVIw動畫在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
@Desdenova已刪除和它的工作發現,但如何在iOS 10中動畫? –
保留塊中的'layoutIfNeeded'位。只是不要在裏面設置常量。 – Desdenova