2012-03-18 24 views
0

我想在UIViewController上製作一個UIWebview。我希望Web視圖僅在網站加載後才顯示。然後,UIWebView將從屏幕底部移動到屏幕的一半。在UIViewController上動畫UIWebView

我是iOS新手。我可以知道我該怎麼做?

此刻,我只能得到Web視圖加載網站...

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSString *fullURL = @"http://www.google.com"; NSURL *url = [NSURL URLWithString:fullURL]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj]; 
} 

回答

2

在viewDidLoad中:你有沒有方法,添加這些行:

webView.hidden = YES; 
webView.delegate = self; // also remember to say you implement UIWebViewDelegate in the .h file 

然後實現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); 
}]; 
1

一個替代方案是用如下:

  1. 聲明的UIWebView的一個實例(@財產和@synthesize)

  2. 把它掛在IB

  3. - viewDidLoad設置其幀送出側的視圖(因此它不能看到)

  4. 把你URLRequest方法在後臺進程(因此它不會阻止用戶界面)

4.1 。這裏是教程http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial

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

5.1。這裏是教程爲http://www.idev101.com/code/User_Interface/UIView/