开发者

Animate embedded UIWebView frame property

after a long search with no results, maybe someone knows an answer to the following problem:

I have a UIView which contains a UIWebView as a subview. The UIView is just a wrapper, so that I can place buttons, etc. on top of the UIWebView. I now want to animate the resizing and repositioning of the UIView AND the UIWebView simultaniously. I want it to look like it was just a UIWebView being resized. I tried various animation techniques: block/commit, implicit/explicit, for example like this:

[UIView beginAnimations:@"zoomIn" context:nil];  
[UIView setAnimationDuration:1.0];  

myWrapperUIView.frame = CGRect(0.0, 0.0, 500.0, 500.0);  
myUIWebView.frame = CGRect(0.0, 0.0, 500.0, 500.0);

[UIView commitAnimations];

but I always get the result that the UIView animates kind of right, but the UIWebView inside just instantly switc开发者_C百科hes to the new frame, so if I zoom from a bigger frame there is empty space around the UIWebView which shrinks during the animation.

I also tried an embedded animation for the UIWebView, but same result.

My Question is:

Is there a way to animate both Views simultaniously, so that at each point in time the UIWebWill be filling the UIView?

Thank you,

Michael


use CGAffineTransform and scale the view using transform property, it will do the job.

myWrapperUIView.frame = CGRect(0.0, 0.0, 500.0, 500.0);  
myUIWebView.frame = CGRect(0.0, 0.0, 500.0, 500.0);
self.window.userInteractionEnabled =NO;
myWrapperUIView.transform = CGAffineTransformMakeScale(0.01, 0.01);
myUIWebView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:ANIMATIONDURATION animations:^{
    myWrapperUIView.transform = CGAffineTransformMakeScale(1.0, 1.0);
    myUIWebView.transform = CGAffineTransformMakeScale(1.0, 1.0);
    }completion:^(BOOL finished) {
      self.window.userInteractionEnabled = YES;
}];

HOPE THIS HELPS,


You must set the autoresizing mask for your web view.

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

@property(nonatomic) UIViewAutoresizing autoresizingMask

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜