2017-11-09 6 views
1

ユーザーがアバターをタップすると、KeyWindow([[[UIApplication sharedApplication ].delegate window ])にシートを追加したい。NSLayoutConstraint NSLayoutConstraint定数を変更するアニメーションの形状を原点から設定したものではなく

シートは、制約の定数を変更することで、原点(左端と下端)からではなく、真っすぐdownToUpになります。 問題が発生することがあります。予期したとおりに動作することもあります。

私はコーディネーターレイアウトが重要だと思います。を作成し、ショー:

my Question Image

は、ここに私のコードです。ここで

@implementation ZBPhotoSheetView 

- (void)awakeFromNib 
{ 
    [super awakeFromNib ]; 
    self.backgroundColor = [[UIColor blackColor ] colorWithAlphaComponent: 0.3 ]; 
    //self.vesselViewBottomConstraint.constant = -150; // add it or not ,don't like it matters. 
} 



+ (ZBPhotoSheetView *)createZhePhotoSheetView 
{ 
    ZBPhotoSheetView * zheSheetView = [[[NSBundle mainBundle ] loadNibNamed:@"ZBPhotoSheetView" owner: nil options: nil ] firstObject ]; 
    return zheSheetView; 
} 


- (void)showZhePhotoSheetView{ 
    if (!_sheetIsShowing){ 
     [[[UIApplication sharedApplication ].delegate window ] addSubview: self ]; 
     self.frame = [UIScreen mainScreen ].bounds; 
     _sheetIsShowing = YES; 

     [UIView animateWithDuration: 0.3f delay:0.f options: UIViewAnimationOptionCurveEaseIn animations:^{ 
      self.vesselViewBottomConstraint.constant = 0; 
      // [self setNeedsUpdateConstraints ]; // add it or not ,don't like it matters. 
      [self layoutIfNeeded]; 
     } completion:^(BOOL finished) {}]; 
    } 
} 

私XIBです:シートは、シーンの底から開始します。

enter image description here

事前に多くのおかげで、:-)

答えて

2

あなたは制約の定数を変更する前に、一度layoutIfNeededを呼び出す必要があります。ビューをウインドウに追加しただけなので、最初の自動レイアウトと制約はアニメーションで一緒になります。これを試して。

- (void)showZhePhotoSheetView{ 
    if (!_sheetIsShowing){ 
     [[[UIApplication sharedApplication ].delegate window ] addSubview: self ]; 
     self.frame = [UIScreen mainScreen ].bounds; 
     _sheetIsShowing = YES; 
     [self layoutIfNeeded]; 

     [UIView animateWithDuration: 0.3f delay:0.f options: UIViewAnimationOptionCurveEaseIn animations:^{ 
      self.vesselViewBottomConstraint.constant = 0; 
      // [self setNeedsUpdateConstraints ]; // add it or not ,don't like it matters. 
      [self layoutIfNeeded]; 
     } completion:^(BOOL finished) {}]; 
    } 
} 
関連する問題