Iphone view got cut off - iphone

My landscape subview is being cut off by the previous view, why is it like that?
Cut off as in the previous view is at the bottom part around 1/3 quarter of the screen even when the new subview is added. Something like this > http://i41.photobucket.com/albums/e253/welzenn99/123.png

you need to set that view's frame in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
OR in
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;

in the method where you tell the subview to come out ([self.view addSubview:someView.view];) add
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)) {
//rotate to landscape
someView.view.frame = CGRectMake(0,0,480,320);
}
else if (orientation == UIDeviceOrientationPortrait) {
//rotate to portrait
isomeView.view.frame = CGRectMake(0,0,320,480);
}
worked for me. good luck

Related

How to resize uiscrollview and its content on the change of orientation in iPhone?

I am working on a project where I have added UIWebviews in the UIscrollview to show the description. I did this because I want to add the swipe effect to move to the new description page. Now, I want to resize that UIscrollview and its content (i.e uiwebview) when the orientation changes (i.e portrait to landscape or Viceversa).
Please give me any sample code or any suggestions for it.
To resize the webview you have to write:-
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
webview.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * someValue1,
scrollView.frame.size.height * someValue2);
}
You can put your code in the following code block :
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if ([self isPadPortrait]) {
// Your code for Portrait
// set frame here
} else if ([self isPadLandscape]) {
// Your code for Landscape
// set frame here
}
and following code will take care of orientation change :
- (BOOL)isPadPortrait
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationPortrait
|| self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
- (BOOL)isPadLandscape
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft));
}
You can set the autoresizingMask of scrollView and add this code to your .m file according to your requirement.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * someValue1,
scrollView.frame.size.height * someValue2);
}
Here is a link to a similar question and their solution:
Scale image to fit screen on iPhone rotation
They used a combination of AutoresizingMasks and ContentModes for both the ScrollView and, in their case, an ImageView, although I imagine the same solution would work for your WebView.
when ever the orientation changed
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
// this delegate method will called if we set should auto orientation return yes;
when ever we changed orientation so set frames..
}
for example
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
appDelegate.interface=interfaceOrientation;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// SET FRAMES FOR LANDSCAPE HERE
}
if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationPortrait)
{
//SET FRAMES FOR Portrait HERE
}
}

Changing iphone orientation, then changing it back cuts my view in half?

I have a view controller in my iphone app setup so that when I change the orientation from portrait to landscape, I change the view. When I change the orientation back from landscape to portrait, the initial view comes back, except this time it is all crammed into the left hand side of the screen. Eventually, when I change orientations enough times everything disappears completely. Is this a common issue beginners have? What could I be doing wrong?
In my root controller I am allowing the orientation to change only when a specific view is being shown with this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (self.currentView == (NSInteger*)Chart || self.currentView == (NSInteger*)Detail) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
return (interfaceOrientation == UIInterfaceOrientationPortrait);
Where self.currentView is an enum of what view I currently have up. The Detail view I want to make sure stays as a portrait view, but when I change the orientation while on that view I want it to change the view to the Graph. Again, this works fine the first time, but when I change back from Graph to Detail, it crams all the controls on the Detail view to the left hand side of the screen.
Here is how I'm changing the view:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if (self.currentView == (NSInteger*)Detail && (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
[[NSNotificationCenter defaultCenter] postNotificationName:#"changeView" object:self userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:Chart] forKey:#"view"]];
}
if (self.currentView == (NSInteger*)Chart && (toInterfaceOrientation == UIInterfaceOrientationPortrait)) {
[[NSNotificationCenter defaultCenter] postNotificationName:#"changeView" object:self userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:Detail] forKey:#"view"]];
}
#justin I once did this which got me into same situation as you are. May be you can check if you haven't done something like this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
CGRect rect;
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
rect = CGRectMake(tableView.frame.origin.x,tableView.frame.origin.y,
tableView.frame.size.width - 50, tableView.frame.size.height - 30);
}
else {
rect = CGRectMake(tableView.frame.origin.x,aBar.frame.origin.y,
tableView.frame.size.width, tableView.frame.size.height);
}
[tableView setFrame:rect];
return YES;
}
All I wanted was a table view with small frame in Portrait mode, without saving the original Frame I was trying to reduce its width and height which eventually brought the table view to a very small size after multiple rotation..
Lolzzz. I should have first saved the original tableview frame and then done something like this
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
tableView.frame = CGRectMake(tableView.frame.origin.x,tableView.frame.origin.y,
tableView.frame.size.width - 50, tableView.frame.size.height - 30);
}
else {
tableView.frame = originalTableViewFrame;
}
check if you have autoresizeSubviews ON (in XIB/Inteface Builder) on your view and possibly parent views and try to turn it off if you are changing frame manually , this solved it for my case

How to change the color of navigataionbar once we turn from landscape to portrait mode and vice varsa in IPhone

Hi Will some body help me
I am using 3.2.5 SDK and 4.2 ISO
Now I am creating a splitViews project but here I am facing problem my problem is that once i am in portrait maid and move other class then i change my portrait mode to landscape at that time my rootview navigation bar color has change But i did not want to change previous i made its green color but after shifting portrait mode to landscape its change please help me some one.
Thanks.....
You could subclass UISplitViewController, and override the willAnimateRotationToInterfaceOrientation:duration: method. For example:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
if([UIDevice currentDevice].orientation == UIInterfaceOrientationPortrait ||
[UIDevice currentDevice].orientation == UIInterfaceOrientationPortraitUpsideDown) {
self.masterNavigationController.navigationBar.tintColor = nil;
} else {
self.masterNavigationController.navigationBar.tintColor = [UIColor colorWithRed:(7.0/255.0) green:(140.0/255.0) blue:(170.0/255.0) alpha:1.0];
}
[super willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration];
}

UITableView in popover doesn't stop scrolling

I have a UITableView being shown in a popover. One cell in my table view has a UITextField in it. When the text field is being edited (the keyboard is visible) and I rotate the device from portrait to landscape and then try to scroll the table view, it keeps going past its bounds, instead of stopping and "bouncing".
Does anyone know how to fix this?
You can try to detect when the device is rotated and call the tableViewController method that adjusts scrolling position of selected cell to the area you need.
You can use following code when rotate device
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if ([appDelegate.aPopover isPopoverVisible])
{
[appDelegate.aPopover dismissPopoverAnimated:NO];
CGSize size = [self rotatedSize];
size.height -= [[self.view viewWithTag:154] frame].size.height;
appDelegate.aPopover.popoverContentSize = size;
[appDelegate.aPopover presentPopoverFromRect:[[self.view viewWithTag:154] frame]
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
}
}
// for set popoverview size when rotate screen
-(CGSize)rotatedSize
{
UIDeviceOrientation orientation1 = [[UIDevice currentDevice] orientation];
UIInterfaceOrientation toInterfaceOrientation = orientation1;
if ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
{
return self.view.frame.size;
}
else
{
return CGSizeMake(self.view.frame.size.height, self.view.frame.size.width);
}
}
Thank you,

Rotate to landscape for views added to the hierarchy manually (iPhone)

I have a simple UIViewController that uses a XIB for its interface.
As such, the interface simply comprises a UIView, a UIActivityIndicator and a UILabel. I have the sizing constraints in Interface Builder set to keep the activity indicator and the label centred when the view rotates.
The UIViewController is set to return YES for portrait and landscape orientations in the -shouldAutorotateToInterfaceOrientation: method.
The view is added to the view hierarchy manually, using
if (!activityOverlay)
activityOverlay = [[XBActivityOverlayViewController alloc] initWithNibName:#"XBActivityOverlayViewController" bundle:nil message:#"Connecting..."];
[activityOverlay.view setAlpha:0.0f];
[self.window addSubview:activityOverlay.view];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
[activityOverlay.view setAlpha:0.9f];
[UIView commitAnimations];
The problem I'm having is that if the device is already in landscape orientation and the view is added to the hierarchy at this point, the view is still in portrait orientation, and doesn't auto rotate.
What do I need to do to add the view in the same orientation as the parent view?
I do not know if it is the right answer to your question but I hope can help:
For me, every time I add/dismiss a modal or display a new view, the following function is called:
-(void) detectOrientation
{
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight))
{
item1.frame = CGRectMake(147.0, 241.0, 56.0, 28.0);
item2.frame = CGRectMake(265.0, 241.0, 56.0, 28.0);
}
else if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) || !inLandscapeOrientation)
{
item1.frame = CGRectMake(35.0, 425.0, 35.0, 28.0);
item2.frame = CGRectMake(176.0, 425.0, 35.0, 28.0);
}
}
Here I change the position according to the current device orientation. Maybe if you detect that the current orientation is landscape you add a subview that has such orientation.
Alejandra :)