xcode 在 UIViewController 上为 UIWebView 设置动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9759596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Animate an UIWebView on the UIViewController
提问by Clarence
I am trying to make a UIWebview on the UIViewController. I want the web view appear only after the web site has been loaded. The UIWebView will then move from the bottom of the screen until half of the screen.
我正在尝试在 UIViewController 上制作 UIWebview。我希望网页视图仅在网站加载后出现。UIWebView 然后将从屏幕底部移动到屏幕的一半。
I am new to animation on iOS. May I know how could i do that?
我是 iOS 动画的新手。我可以知道我怎么做吗?
At the moment, i only can get the web view loading the website...
目前,我只能获取加载网站的网页视图...
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *fullURL = @"http://www.google.com"; NSURL *url = [NSURL URLWithString:fullURL]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj];
}
回答by hsdev
In the viewDidLoad: method you have there, add these lines:
在 viewDidLoad: 方法中,添加以下几行:
webView.hidden = YES;
webView.delegate = self; // also remember to say you implement UIWebViewDelegate in the .h file
Then implement the webViewDidFinishLoad: delegate method, where you insert something like the following:
然后实现 webViewDidFinishLoad: 委托方法,在其中插入如下内容:
webView.frame = CGRectMake(someX, self.view.frame.size.height, someWidth, someHeight);
webView.hidden = NO;
[UIView animateWithDuration:1.0 animations:^{
webView.frame = CGRectMake(someX, self.view.frame.size.height/2, someWidth, someHeight);
}];
回答by Canopus
One alternative is using the followings:
一种替代方法是使用以下方法:
Declare an instance of UIWebView (@property and @synthesize)
Hook it up in IB
In
- viewDidLoad
set its frame out side of the view (so it can not be seen)Put your
URLRequest
method in a background process (so it doesn't block the UI)
声明一个 UIWebView 实例(@property 和 @synthesize)
将其连接到 IB
在
- viewDidLoad
设置其帧缩小视图的侧(所以它不能被看见)将您的
URLRequest
方法放在后台进程中(这样它就不会阻塞 UI)
4.1. Here is tutorial for that http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial
4.1. 这是http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial 的教程
5.Once it is loaded call the method to push the webView into the visible view. e.g.
5. 加载后调用方法将 webView 推送到可见视图中。例如
- (void) pushWebView { [UIView beginAnimations:@"Pop WebView" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:0.5]; [self.webView setFrame:<frame>]; // or use CGAffineTransform [UIView commitAnimations]; }
- (void) pushWebView { [UIView beginAnimations:@"Pop WebView" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:0.5]; [self.webView setFrame:<frame>]; // or use CGAffineTransform [UIView commitAnimations]; }
5.1. Here is tutorial for that http://www.idev101.com/code/User_Interface/UIView/
5.1. 这是http://www.idev101.com/code/User_Interface/UIView/ 的教程