gpt4 book ai didi

ios - NSLayoutConstraint,从原点更改常量动画,不是我设置的

转载 作者:行者123 更新时间:2023-12-01 19:48:23 26 4
gpt4 key购买 nike

我想在 KeyWindow( [[[UIApplication sharedApplication ].delegate window ] ) 中添加一个工作表,当用户点击头像时会有动画。

通过更改约束的常数,我希望工作表直接显示 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

最佳答案

您需要调用layoutIfNeeded在更改约束常数之前一次。您刚刚在窗口中添加了 View ,因此初始自动布局和您的约束在动画中一起发生变化。试试这个。

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

关于ios - NSLayoutConstraint,从原点更改常量动画,不是我设置的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47195521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com