hi all i am playing YouTube videos in ipad and iphone it is universal app.in iphone it is showing controlles but in ipad it is not showing the controllers.the code what i have writeen is as below.
-(void)viewWillAppear:(BOOL)animated
{if(self.interfaceOrientation == UIInterfaceOrientationPortrait||self.interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(#" before portrait videowebveiw frame is %f %f %f %f",self.videowebveiw.frame.origin.x,self.videowebveiw.frame.origin.y,self.videowebveiw.frame.size.width,self.videowebveiw.frame.size.height);
CGRect webviewframe=self.videowebveiw.frame;
webviewframe.size.width=748.0;
webviewframe.size.height=1024.0;
self.videowebveiw.frame=webviewframe;
embedHTML=[NSString stringWithFormat:#"<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=768.0 height=1024.0></embed></body></html>",self.weburl];
NSLog(#" after portrait videowebveiw frame is %f %f %f %f",self.videowebveiw.frame.origin.x,self.videowebveiw.frame.origin.y,self.videowebveiw.frame.size.width,self.videowebveiw.frame.size.height);
}
else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft||self.interfaceOrientation== UIInterfaceOrientationLandscapeRight)
{
NSLog(#" before landscape webview frame is %f %f %f %f",self.videowebveiw.frame.origin.x,self.videowebveiw.frame.origin.y,self.videowebveiw.frame.size.width,self.videowebveiw.frame.size.height);
CGRect webviewframe=self.videowebveiw.frame;
webviewframe.size.width=1024.0;
webviewframe.size.height=748.0;
self.videowebveiw.frame=webviewframe;
embedHTML=[NSString stringWithFormat:#"<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=1024.0 height=768.0></embed></body></html>",self.weburl];
NSLog(#" After landscape webview frame is %f %f %f %f",self.videowebveiw.frame.origin.x,self.videowebveiw.frame.origin.y,self.videowebveiw.frame.size.width,self.videowebveiw.frame.size.height);
}
[self loadwebview];
}
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait||toInterfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(#" before portrait videowebveiw frame is %f %f %f %f",self.videowebveiw.frame.origin.x,self.videowebveiw.frame.origin.y,self.videowebveiw.frame.size.width,self.videowebveiw.frame.size.height);
CGRect webviewframe=self.videowebveiw.frame;
webviewframe.size.width=748.0;
webviewframe.size.height=1024.0;
self.videowebveiw.frame=webviewframe;
embedHTML=[NSString stringWithFormat:#"<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=768.0 height=1024.0></embed></body></html>",self.weburl];
NSLog(#" after portrait videowebveiw frame is %f %f %f %f",self.videowebveiw.frame.origin.x,self.videowebveiw.frame.origin.y,self.videowebveiw.frame.size.width,self.videowebveiw.frame.size.height);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft||toInterfaceOrientation== UIInterfaceOrientationLandscapeRight)
{
NSLog(#" before landscape webview frame is %f %f %f %f",self.videowebveiw.frame.origin.x,self.videowebveiw.frame.origin.y,self.videowebveiw.frame.size.width,self.videowebveiw.frame.size.height);
CGRect webviewframe=self.videowebveiw.frame;
webviewframe.size.width=1024.0;
webviewframe.size.height=748.0;
self.videowebveiw.frame=webviewframe;
embedHTML=[NSString stringWithFormat:#"<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=1024.0 height=768.0></embed></body></html>",self.weburl];
NSLog(#" After landscape webview frame is %f %f %f %f",self.videowebveiw.frame.origin.x,self.videowebveiw.frame.origin.y,self.videowebveiw.frame.size.width,self.videowebveiw.frame.size.height);
}
}
Related
I see two different behaviors for CGAffineTransformMakeTranslation between simulator mode and the real device.
(on iOS 8.1)
For an iPhone4, to get CGAffineTransformMakeTranslation to work on the real device, I have to translate by twice the amount.
On the iPhone4s simulator, I have to translate just by the amount with not scaling.
Perhaps I'm missing something obvious but since both have the same number of logical pixels, I shouldn't have to adjust CGAffineTransformMakeTranslation to make translation work.
Here I have a view I'm pulling in and out of view by swiping:
CGRect menuOrigin = self.rootController.containerView.bounds;
switch (direction) {
case UISwipeGestureRecognizerDirectionLeft:
{
NSLog(#"Initial Position: %#", NSStringFromCGPoint(self.rootController.containerView.frame.origin));
NSLog(#"Initial Scale: %f", [self contentScaleFactor]);
NSLog(#"Initial Center: %#", NSStringFromCGPoint([self center]));
CGAffineTransform transform = CGAffineTransformMakeTranslation(-1.0 * widthToSlide, 0);
self.rootController.containerView.transform = transform;
[UIView animateWithDuration:0.4 animations:^{
self.rootController.containerView.transform = transform;
[self.rootController.containerView layoutIfNeeded];
} completion:^(BOOL finished) {
NSLog(#"Final Position: %#", NSStringFromCGPoint(self.rootController.containerView.frame.origin));
NSLog(#"Final Scale: %f", [self contentScaleFactor]);
NSLog(#"Final Center: %#", NSStringFromCGPoint([self center]));
}];
}
break;
case UISwipeGestureRecognizerDirectionRight:
{
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 0.0);
[UIView animateWithDuration:0.4 animations:^{
self.rootController.containerView.transform = transform;
[self.rootController.containerView layoutIfNeeded];
} completion:^(BOOL finished) {
}];
}
default:
break;
}
[self.rootController.containerView setNeedsDisplay];
[self setNeedsDisplay];
NSLog goes like this for the iPhone4 real device:
2015-10-15 01:12:37.547 Local[5307:60b] swipeLocalPull adjusting width 183
2015-10-15 01:12:37.556 Local[5307:60b] Screen size: {320, 480}
2015-10-15 01:12:37.559 Local[5307:60b] Initial Position: {0, 66}
2015-10-15 01:12:37.974 Local[5307:60b] Final Position: {-91.5, 66}
and for the iPhone4s iOS 8.1 simulator:
2015-10-15 01:19:19.479 Local[56380:3061577] swipeLocalPull adjusting width 183
2015-10-15 01:19:19.480 Local[56380:3061577] Screen size: {320, 480}
2015-10-15 01:19:19.480 Local[56380:3061577] Initial Position: {0, 66}
2015-10-15 01:19:19.886 Local[56380:3061577] Final Position: {-183, 66}
The simulator is translated correctly. Notice, the real device translated only half way to -91.5. Why is this and how can I detect or compensate for this. Sorry if this question has been asked before but I could not find the root cause for this behavior. I only care about x translation at this moment.
Anyone have clues for this behavior.?
Update
By request, here's a few extra outputs:
---iPhone4 values---
2015-10-15 17:20:59.591 Local[5617:60b] swipeLocalPull adjusting width 183
2015-10-15 17:20:59.596 Local[5617:60b] Screen size: {320, 480}
2015-10-15 17:20:59.599 Local[5617:60b] Initial Position: {0, 66}
2015-10-15 17:20:59.601 Local[5617:60b] Initial Scale: 2.000000
2015-10-15 17:20:59.603 Local[5617:60b] Initial Center: {201, 99}
2015-10-15 17:21:00.015 Local[5617:60b] Final Position: {-91.5, 66}
2015-10-15 17:21:00.018 Local[5617:60b] Final Scale: 2.000000
2015-10-15 17:21:00.037 Local[5617:60b] Final Center: {201, 99}
---iPhone4s Simulator---
2015-10-15 17:39:59.850 Local[57069:3104390] swipeLocalPull adjusting width 183
2015-10-15 17:39:59.851 Local[57069:3104390] Screen size: {320, 480}
2015-10-15 17:39:59.851 Local[57069:3104390] Initial Position: {0, 66}
2015-10-15 17:39:59.851 Local[57069:3104390] Initial Scale: 2.000000
2015-10-15 17:39:59.851 Local[57069:3104390] Initial Center: {201, 99}
2015-10-15 17:39:59.852 Local[57069:3104390] Final Position: {-183, 66}
2015-10-15 17:39:59.852 Local[57069:3104390] Final Scale: 2.000000
2015-10-15 17:39:59.852 Local[57069:3104390] Final Center: {201, 99}
They both seem to be at #2x scale so I expect the same code to work for both.
Working Code
I got it to work with the following(if someone explains why, then I'll just mark that as the answer):
switch (direction) {
case UISwipeGestureRecognizerDirectionLeft:
{
NSLog(#"Initial Position: %#", NSStringFromCGPoint(self.rootController.containerView.frame.origin));
NSLog(#"Initial Scale: %f", [self contentScaleFactor]);
NSLog(#"Initial Center: %#", NSStringFromCGPoint([self center]));
CGPoint currentPos = self.rootController.containerView.center;
currentPos.x -= widthToSlide;
[UIView animateWithDuration: .4
delay: 0
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
self.rootController.containerView.center = currentPos;
}
completion:^(BOOL finished) { }
];
}
break;
case UISwipeGestureRecognizerDirectionRight:
{
CGPoint currentPos = self.rootController.containerView.center;
currentPos.x += widthToSlide;
[UIView animateWithDuration: .4
delay: 0
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
self.rootController.containerView.center = currentPos;
}
completion:^(BOOL finished) { }
];
}
default:
break;
}
[self.rootController.containerView setNeedsDisplay];
[self setNeedsDisplay];
I have taken a web view and load html like this
NSMutableString *myDescriptionHTML = [NSMutableString stringWithFormat:#"<html> \n"
"<head> \n"
"<style type=\"text/css\"> \n"
"body {font-family: \"%#\"; font-size: %#;}\n"
"</style> \n"
"</head> \n"
"<body>%#</body> \n"
"</html>", #"helvetica", [NSNumber numberWithInt:40], messageModel.content];
i want to set web view height to web view content size height after web view loaded html content
Tried ways
1)
CGRect frame = self.webViewMain.frame;
frame.size.height = 1;
self.webViewMain.frame = frame;
CGSize fittingSize = [self.webViewMain sizeThatFits:CGSizeZero];
frame.size = fittingSize;
self.webViewMain.frame = frame;
Height = fittingSize.height;
NSLog(#"size: %f, %f", fittingSize.width, fittingSize.height);
[tableViewMain reloadData];
its too long height
2)
Height = [[self.webViewMain stringByEvaluatingJavaScriptFromString:#"document.documentElement.scrollHeight;"] floatValue];
3)
Heiht = self.webViewMain.scrollView.contentSize.Height
But no one is actual height
help me thanks....
UIWebview is a subclass of UIScrollview so you can set Webview.content size using CGSize. That will set your web view content height and width as required.
I had created a Viewcontroller in XCode, everything is working fine. When a phone call comes, the in Call Status bar is pushing the button in the bottom of the view "DOWN" due to that I am unable to click the button during the phone call.
I would like to know how to keep the buttons in the bottom, the same position even when the phone call comes. I tried several methods nothing worked for me.
- (void)statusBarFrameWillChange:(NSNotification*)notification {
NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
CGRect newFrame;
[rectValue getValue:&newFrame];
CGRect fixedFrame = bottomBar.frame;
fixedFrame.origin.y = fixedFrame.origin.y - newFrame.size.height; //Keep the Y position as it is
bottomBar.frame = fixedFrame;
NSLog(#"statusBarFrameWillChange: newSize %f, %f, %f", fixedFrame.origin.y, newFrame.size.width, newFrame.size.height);
}
- (void)statusBarFrameChanged:(NSNotification*)notification {
NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
CGRect oldFrame;
[rectValue getValue:&oldFrame];
CGRect fixedFrame = bottomBar.frame;
fixedFrame.origin.y = fixedFrame.origin.y + oldFrame.size.height;
bottomBar.frame = fixedFrame;
NSLog(#"statusBarFrameChanged: oldSize %f, %f, %f", fixedFrame.origin.y, oldFrame.size.width, oldFrame.size.height);
}
Using autolayout, make sure you set a Bottom Space constraint:
In my iOS app I'm trying to perform following simple animation:
- (void)dismissToolbar
{
NSLog(#"bx: %f by: %f bw: %f bh: %f ",
toolbar.frame.origin.x,
toolbar.frame.origin.y,
toolbar.frame.size.width,
toolbar.frame.size.height);
CGRect tempRect = CGRectMake(0,
toolbar.frame.origin.y + toolbar.frame.size.height,
toolbar.frame.size.width,
toolbar.frame.size.height);
[UIView animateWithDuration:animationsDuration
delay:0
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowAnimatedContent
animations:^{
NSLog(#"bx: %f by: %f bw: %f bh: %f ",
tempRect.origin.x,
tempRect.origin.y,
tempRect.size.width,
tempRect.size.height);
toolbar.frame = tempRect; // frame value doesn't change here!
}
completion:^(BOOL finished) {
NSLog(#"bx: %f by: %f bw: %f bh: %f ",
toolbar.frame.origin.x,
toolbar.frame.origin.y,
toolbar.frame.size.width,
toolbar.frame.size.height);
NSLog(#"dismiss toolbar complete");
[toolbar setHidden:YES];
isPlayerToolbarActive = NO;
isDissmissingToolbar = NO;
}
];
[[NSNotificationCenter defaultCenter] postNotificationName:#"animateSidePanels" object:#"removingPlayerToolbar"];
}
I'm getting the following output to a console from the logs above:
bx: 0.000000 by: 724.000000 bw: 1024.000000 bh: 44.000000
bx: 0.000000 by: 768.000000 bw: 1024.000000 bh: 44.000000
bx: 0.000000 by: 724.000000 bw: 1024.000000 bh: 44.000000
dismiss toolbar complete
as you can see the value of the frame didn't change...and I don't really understand why...
any kind of help is highly appreciated!
Did you create the view with xib's or interfaceBuilder?
If so, try selecting the xib and deselecting use autoLayout
I am developing and app which i want a youtube video in a page.
It works fine withe the code below:
-(void)viewDidLoad{
[super viewDidLoad];
}
- (void) viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.47 green:.43 blue:.4 alpha:1];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
NSString *htmlString;
if(interfaceOrientation == UIInterfaceOrientationPortrait){
htmlString = [NSString stringWithFormat:#"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 20\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"768\" height=\"960\"><param name=\"movie\" value=\"%#\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%#\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"768\" height=\"960\"></embed></object></div></body></html>",urlToOpen,urlToOpen];
}else{
htmlString = [NSString stringWithFormat:#"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"1024\" height=\"704\"><param name=\"movie\" value=\"%#\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%#\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"1024\" height=\"704\"></embed></object></div></body></html>",urlToOpen,urlToOpen];
}
[self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:#"http://www.youtube.com"]];
return YES;
}
The view is working fine in portrait and in landscape.
The problem is when i see the video with the full Screen and i Rotate. Whe i finish the full screen, the webview didn't detect the rotation and print the webview as the wrong way.
How could i detect the Youtube full screen is rotating for rotate my view?
Thankyou
set content width to 100%
my template
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \
<html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> \
<meta name=\"viewport\" content=\"width=320\"> \
<style> \
html,body {-webkit-text-size-adjust: none; size:100%%} \
body {margin: 0; padding: 0;width:100%;} \
table { font-family:Georgia; font-size:%dpt; border-style: none; size:100%%} \
</style> </head>
....
I'm assuming your already handling the orientation callbacks? (shouldAutorotateToInterfaceOrientation, didRotateFromInterfaceOrientation)
When the YouTube video finishes and focus is returned to your app, the viewWillAppear method should be called. In there, you can get the device orientation:
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
Then perform your layout changes. This also would handle the layout when this view first opens.
You could do it in a switch statement:
switch(orientation) {
case UIInterfaceOrientationLandscapeLeft: //layout for this landscape mode
case UIInterfaceOrientationPortraitUpsideDown: //layout for this portrait mode
I handled that problem using NSNotification like this
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidExitFullScreen)
name:#"UIMoviePlayerControllerDidExitFullscreenNotification"
object:nil];
and method that will be called is
- (void)moviePlayerDidExitFullScreen
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
}
Hope that Helps