3
我想從我的viewController底部UIWebView動畫,並且我正在使用砌體(https://github.com/Masonry/Masonry)。砌體animationWithDuration不動畫
我最初創建了我的webview,大小爲0 - (x,y,height和width),然後我嘗試對它進行動畫處理,以便webview在viewcontroller的頂部生成動畫。 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...
}
謝謝!我總是忘記'layoutIfNeeded'應該在** parentView **上調用,而不是在動畫視圖本身上調用 – 2015-10-15 13:43:46