Unexpected behavior of a Modal View displaying a YouTube video in a UIWebView - uiwebview

I have a view based application (no storyboards) with a button that presents a modal view with a webview in it. The webview loads a YouTube video and the user taps it and watches the video in full screen.
When the video ends (or the user taps "done"), the video player dismisses, but for some reason I see the Main View instead of the modal view controller (and I can't invoke the modal view again with the button, although the IBAction is being called)...
The present modal view code (in the Main View controller):
SomeViewController *controller = [[[SomeViewController alloc] initWithNibName:#"SomeViewController_iPhone" bundle:nil] autorelease];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
Then, in "SomeViewController", I have a UIWebView that loads the YouTube video:
- (void)embedYouTube:(NSString *)urlString 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];
[self.webView loadHTMLString:html baseURL:nil];
}
The video plays just fine, but when it's done, it's get dismissed and the Main View is being showed instead of the Modal View (SomeViewController).
No error is being given though.
From what I understand, the video player is also a modal view, so the hierarchy is something like this:
-- Main View
---- Modal View (SomeViewController with WebView)
-------- Video Modal View (invoked by the WebView)
So I don't get why is the Main View controller being shown after the Video is done playing, and why it doesn't let me invoke the modal view controller again...
Thanks for any help!

Related

I want to open a web view instead of Browser whenever I click link on my textView

I have a lot of input text that contains linked URL on the textview field. I just want to set to default whenever I clicked any link on the textview it will pop up the webView instead of the browser.Thanks
https://developer.apple.com/library/ios/documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html
you can use this function from UITextViewDelegate:
(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{
NSLog(#"URL %#",URL); // URL
// pop webkit
return NO;
}

MFSideMenu in UINavigationController not working when introduced with a modal Segue

I'm trying to integrate MFSideMenu in my project but I don't want to adopt the approach described in the GitHub depository as it defines the menu in the app delegate.
I have a login screen which will introduce a navigation controller with the main page as reported in this picture
I would like to add the support for MFSideMenu in the navigationcontroller root controller using this code:
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
// Custom initialization
self.sideMenuController = [[SideMenuViewController alloc] init];
UINavigationController *navigationController = self.navigationController;
MFSideMenuOptions options = MFSideMenuOptionMenuButtonEnabled|MFSideMenuOptionBackButtonEnabled
|MFSideMenuOptionShadowEnabled;
MFSideMenuPanMode panMode = MFSideMenuPanModeNavigationBar|MFSideMenuPanModeNavigationController;
MFSideMenu *sideMenu = [MFSideMenu menuWithNavigationController:navigationController
sideMenuController:sideMenuController
location:MFSideMenuLocationLeft
options:options
panMode:panMode];
sideMenuController.sideMenu = sideMenu;
}
return self;
}
When I run the app the menu button appears in my navigation bar and everything seems working fine but,if I introduce the navigation controller through a modal segue (i.e. a login screen which goes to the navigation controller in case of a correct login) the button disappears.
Any idea about how to fix it?

loading uiwebview from specified location

//Move to bookmarked place if page is opened from bookmark section.
- (void)webViewDidFinishLoad:(UIWebView *)webView1;
{
if(chkview == 2)
{
//Move webview to chkScrollValue position.
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"document.body.scrollTop = %d", chkScrollValue]];
// [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollBy(0,%d);",chkScrollValue]];
}
}
I'm loading my webview which was displaying html which was in resources folder and it was working fine. Now, i'm using javascript with html and this is not working anymore.
I got the solution. I was performing this task after webViewDidFinishLoad. Rather than that now I added another function and added this code in function
[self performSelector:#selector(loadBookmark) withObject:nil afterDelay:0.4];

How to implement event handling in uiwebview?

I have taken a webview to show some HTML content in iPhone. Now I want to put some action on user events on the phone. I want to trace the tap event done on the screen by the user on that web view.
For this I have added a method
-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event {
in my code.
But the problem is when I click outside the webview it works perfectly. Bt when I tap on the web view, it does not respond. So, please tell me what should I do to acheive tap event trace on that particular web view.
Help me out.
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
if ([[url lastPathComponent] isEqual:#"testmessage"]) {
NSLog(#"Nya");
return NO;
}
return YES;
}
HTML
<a href='testmessage'>Test</a>
or
<script>
function callObjc(){
document.location = 'testmessage';
}
</script>
<a onclick='callObjc();'>Test</a>

iPad - find the true height of a UIWebView

I work for a media company, and in our iPad application we're upgrading our content so it looks better. Previously, we used a UILabel to display the contents of our posts. I used this to get the actual height of my UILabel:
CGSize expectedSize = [label.text sizeWithFont:label.font
constrainedToSize:maximumLabelSize lineBreakMode:label.lineBreakMode];
However, we changed our posts' content to HTML, so I'm using a UIWebView. Is there a way to find the true height of the UIWebView, like I do with the UILabel?
Unlike with a plain string, you'll probably only be able to get the height once the web view finishes rendering. Here's how you can do it in a web view delegate method:
- (void)webViewDidFinishLoad:(UIWebView *)webview
{
NSString *heightString = [webview stringByEvaluatingJavaScriptFromString:
#"document.body.clientHeight"];
int height = [heightString intValue];
...
}

Resources