After YouTube video play app doesn't come back in the same position
So I managed to play an embeded youtube video in my app. After I press 'done' the app doesn't come back in the same position where it was before playing the video. Please help me with this. This is the way I do it.
- (void)embedYouTube:(NSString *)u开发者_StackOverflowrlString frame:(CGRect)frame
{
NSString *embedHTML = @"\
<html><head>\
style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
videoView.center=CGPointMake(160, 240);
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
}
My problem was that I had a view which I presented modally. In this case, when youtube goes away and your app comes back to foreground it won't come back in the same position, but in the position before presenting the modal. So I solved my problem by adding that view as a subview rather than presenting it modally.
精彩评论