ipad - youtube in iframe via uiwebview specify dimensions that don't cut off when rotated to landscape -
i'm making ipad app loads youtube video. able uiwebview load youtube video iframe code found online. need able rotate ipad , not have video cropped when rotated landscape @ same time both landscape , portrait width full width of device. put in iframe? i've tried use
"meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no"
but didn't work. tried place in iframe script (not between within . cannot right. ideas? appreciated. here's code below:
.m
#import "viewcontroller.h" #import <avfoundation/avfoundation.h> @interface viewcontroller () @end @implementation viewcontroller @synthesize webview; -(void)viewdidload { [super viewdidload]; [self embedyoutube]; nslog(@"frame:%@", nsstringfromcgrect(self.view.frame)); // prints frame:{{0, 0}, {768, 1004}} nslog(@"bounds:%@", nsstringfromcgrect([[self view] bounds])); // prints frame:{{0, 0}, {768, 1004}} } -(void)embedyoutube{ avaudiosession *audiosession = [avaudiosession sharedinstance]; bool ok; nserror *setcategoryerror = nil; ok = [audiosession setcategory:avaudiosessioncategoryplayback error:&setcategoryerror]; if (!ok) { nslog(@"%s setcategoryerror=%@", __pretty_function__, setcategoryerror); } nsstring *embedhtml = @"<iframe height=\"700\" width=\"900\" src=\"http://www.youtube.com/embed/qk8mjjjvaes\" frameborder=\"0\" allowfullscreen></iframe>"; nsstring *html = [nsstring stringwithformat:embedhtml]; [webview loadhtmlstring:html baseurl:nil]; [self.view addsubview:webview]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } @end
in appdelegate.m file, have:
- (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation { // support rotation in view controller return yes; }
.xib
both view , webview have autoresize subviews checked, orientation view portrait, size view none, both mode center , webview scales fit page.
i ended figuring out exact dimensions give xcode aspect ratio calculator.
-(void)embedyoutube{ avaudiosession *audiosession = [avaudiosession sharedinstance]; bool ok; nserror *setcategoryerror = nil; ok = [audiosession setcategory:avaudiosessioncategoryplayback error:&setcategoryerror]; if (!ok) { nslog(@"%s setcategoryerror=%@", __pretty_function__, setcategoryerror); } nsstring *embedhtml = @"<iframe height=\"548\" width=\"975\" src=\"http://www.youtube.com/embed/qk8mjjjvaes\" frameborder=\"0\" allowfullscreen></iframe>"; nsstring *html = [nsstring stringwithformat:embedhtml]; [webview loadhtmlstring:html baseurl:nil]; [self.view addsubview:webview]; }
Comments
Post a Comment