gpt4 book ai didi

ios - 砌体 animationWithDuration 没有动画

转载 作者:可可西里 更新时间:2023-11-01 06:18:26 24 4
gpt4 key购买 nike

我正在尝试从我的 viewController 顶部的底部为 UIWebView 设置动画,并且我正在使用砌体 ( https://github.com/Masonry/Masonry)。

我最初创建大小为 0 - (x,y,height and width) 的 webview,然后尝试为其设置动画,以便 webview 在 vi​​ewcontroller 的“顶部”设置动画。显示了 WebView ,但它没有在适当的位置设置动画 - 它只是立即出现。任何有经验的人都可以指导我正确的方向吗?

这是我的按钮操作

-(void)didPressBtn{
self.infoView = [UIWebView new];
self.infoView.scalesPageToFit = YES;
self.infoView.backgroundColor = [UIColor whiteColor];
self.infoView.delegate = self;
[self.scrollView addSubview:self.infoView];
[self.infoView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(@(0));
}];


[self.scrollView layoutIfNeeded];
//FIXME: Hmmm it doesn't really animate!?
[UIView animateWithDuration:1 animations:^{
[self.scrollView setContentOffset:CGPointMake(0, 0)];
[self.infoView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
}];

[self.scrollView layoutIfNeeded];

} completion:^(BOOL finished) {
[self.infoView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:NSLocalizedString(@"INFORMATION_URL", )] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:15]];
}];
}

我的viewDidLoad

- (void)viewDidLoad
{
[super viewDidLoad];

self.scrollView = [UIScrollView new];
self.scrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.scrollView];
[self.scrollView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];

UIView *contentView = [UIView new];
[self.scrollView addSubview:contentView];

[contentView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
}];

//Then adding buttons and such...
}

最佳答案

关于 didPressButton 的快速观察。您正在使用 mas_makeConstraints 将边设置为等于 @0,然后立即再次使用 mas_makeConstraints 更改它们,以便填充 ScrollView 。这在第一组之上添加了相互矛盾的约束。

相反,您可以使用 mas_remakeConstraints 替换该 View 上的现有约束。

至于动画,我使用的模式是先更新约束(不在动画 block 内),然后为布局设置动画:

[UIView animateWithDuration:1
animations:^{
[theParentView layoutIfNeeded];
}];

另见 How do I animate constraint changes?

关于ios - 砌体 animationWithDuration 没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26722357/

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