2016-10-14 30 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]; 
    }]; 
}