2016-10-14 29 views
3

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]; 
    }]; 
} 

enter image description here

+0

不要更新动画块中的约束常量。 – Desdenova

+0

@Desdenova已删除和它的工作发现,但如何在iOS 10中动画? –

+0

保留块中的'layoutIfNeeded'位。只是不要在里面设置常量。 – Desdenova

回答

1

只需使用此代码

- (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]; 
    }]; 
} 

希望它会为你的作品。 ;)

快乐编码!

+0

此代码无法使用。 –

+0

发生了什么,与以前相同的结果或任何更改? –

+0

与前面相同的结果。 –

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) { 
}]; 

} 
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]; 
    }]; 
}