Clarence
Clarence

Reputation: 1943

Animate an UIWebView on the UIViewController

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.

I am new to animation on iOS. May I know how could i do that?

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];
} 

Upvotes: 0

Views: 5334

Answers (2)

hsdev
hsdev

Reputation: 507

In the viewDidLoad: method you have there, add these lines:

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:

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

Upvotes: 2

Sierra Alpha
Sierra Alpha

Reputation: 3727

One alternative is using the followings:

  1. Declare an instance of UIWebView (@property and @synthesize)

  2. Hook it up in IB

  3. In - viewDidLoad set its frame out side of the view (so it can not be seen)

  4. Put your URLRequest method in a background process (so it doesn't block the UI)

4.1. Here is tutorial for that 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.

- (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/

Upvotes: 1

Related Questions