ipad orientation issue with modelview - objective-c

I have button in main view,when i click on main view button model view Mv1 is open.Mv1 model view width and height is 730 and 620.in portrait mode Mv1 model view show center in main view but in landscape mode Mv1 model view show center horizontally but does not show center vertically in main view.
main view button click coding:-
Mv1 *Mv1obj = [[Mv1 alloc]initWithNibName:#"Mv1" bundle:nil];
UINavigationController*nav[[UINavigationControlleralloc]initWithRootViewController:Mv1obj];
nav.modalPresentationStyle=UIModalPresentationFormSheet;
nav.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nav animated:YES];
nav.view.superview.frame = CGRectMake(0, 0,730,620);
nav.view.superview.center = self.view.center;
if know please replay,thanks in advance.

The issue here is that you need to account for orientation when setting the center, so replace the line:
nav.view.superview.center = self.view.center;
with something like
UIDeviceOrientation orientation = ([[UIDevice currentDevice] orientation]);
const CGPoint centerPortait = self.view.center;
const CGPoint centerLandscape = CGPointMake(centerPortait.y, centerPortait.x);
const CGPoint center = (orientation == UIDeviceOrientationPortrait) ? centerPortait : centerLandscape;
nav.view.superview.center = center;
this will correctly center the modal view.

Related

Keep UICollectionViewCell centered after Zooming with UIPinchGestureRecognizer

I'm having this issue. I change the scale and as well the transition of the view of a UICollectionViewCell, for doing zoom in the position of my fingers do the UIPinchGesture. But after that, the position of the view changes and the view go off the screen and its bounds. I want that the Gesture View get back to its correct position.
This is what is happening:
I have tried to assign a CGAffineTransformIdentity to the view if the center of the cell changes, but after the Scale and the Translate, its center always changes, so its frame as well.
The code in UIGestureRecognizerStateEnded:
if ([gesture state] == UIGestureRecognizerStateEnded){
//Get the Cell that is getting zoomed
CGPoint initialPinchPoint = [gesture locationInView:self.collectionView];
NSIndexPath* pinchedCellPath = [self.collectionView indexPathForItemAtPoint:initialPinchPoint];
SBQPhotosDetailCollectionViewCell *cell=[[SBQPhotosDetailCollectionViewCell alloc] init];
cell=(SBQPhotosDetailCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:pinchedCellPath];
//Check ifs frame with the gesture of the Pinch
if ((cell.frame.origin.x != [gesture view].frame.origin.x) || (cell.frame.origin.y != [gesture view].frame.origin.y)){
[gesture view].transform = CGAffineTransformIdentity;
}
}
I would like to apply the CGAffineTransformIdentity only if the view of the Gesture change its center, position, but not if the view got zoomed.
Thanks

Change height of UIView

I have an UIViewController with TableView which is showed when I pressed Button in another View. It slides correctly from the bottom of the screen, but I want its height to be half of screen height and stays at the bottom of the screen.
How can I get this?
Here is my code:
CupsViewController
This is the code when Button is pressed for showing TableView.
//DirectionViewController is the one that contains TableView
DirectionViewController *directionController = [self.storyboard instantiateViewControllerWithIdentifier:#"directionsView"];
// Position the options at bottom of screen
CGRect optionsFrame = directionController.view.frame;
optionsFrame.origin.x = 0;
optionsFrame.size.width = 320;
optionsFrame.origin.y = 423;
// For the animation, move the view up by its own height.
optionsFrame.origin.y += optionsFrame.size.height;
directionController.view.frame = optionsFrame;
[UIView beginAnimations:nil context:nil];
optionsFrame.origin.y -= optionsFrame.size.height;
directionController.view.frame = optionsFrame;
[UIView commitAnimations];
[self.navigationController pushViewController:directionController animated:YES];
Set the options frame height to half of screen size in your animation code.
Hope this is what you are looking for
https://github.com/slysid/iOS/tree/master/HalfTable
/Bharath

UIView cut off in landscape mode

I have several UIViews added as subViews to my main view controller. The way I have the views laid out looks fine in portrait mode, however, when it is tilted in to landscape mode, the bottom parts of the subviews gets cut off. I figured if I set the height of the frame, it would allow the screen to scroll and thus reveal the parts of the subViews that were cut off - but it doesn't.
- (void)didRotate:(NSNotification *)notification {
UIDeviceOrientation orientation = [[notification object] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft) {
self.view.frame = CGRectMake(0.0, 0.0, 1024.0, maxHeight);
} else if (orientation == UIDeviceOrientationLandscapeRight) {
self.view.frame = CGRectMake(0.0, 0.0, 1024.0, maxHeight);
}
}
I also tried adding a UIScrollView to the main view, then adding the afore mentioned subViews to the scrollView
- (void)viewDidLoad
{
scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
[self.view addSubview:scrollView];
//add views to scrollView
[super viewDidLoad];
}
How can I make the main view "scroll" if the sub-views exceed the screen size?
After you add your views to the scroll view, you must set the contentSize property of the scroll view so that the scroll view knows there's content to be scrolled to.

UIScrollView placement on master view of a split view controller

I am having a weird issue. I have a split view controller and in the detail view I have a scroll view. Inside the scroll view I have a lavel with some information.
When the application first opens in landscape, the scroll view is always placed 1/2 way down the view of the detail view. When I touch an item in the root view and the next view shows, then I return to the scroll view, the scroll view is in the correct place (10,10).
I have set the frame of the scroll view in the viewWillAppear method of the detail view. Here is my code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) ||
([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)) {
[self setPortrait];
CGRect tmpR = [self.view frame];
NSLog(#"The Detail View Controller Portrait view: width: %f height: %f",tmpR.size.width, tmpR.size.height);
} else {
[self setLandscape];
CGRect tmpR = [self.view frame];
NSLog(#"The Detail View Controller Portrait view: width: %f height: %f",tmpR.size.width, tmpR.size.height);
}
// show the front page message....
[self setMessage:kDetailViewMessage];
// make sure the scroll is at the top....
[scrollView setContentOffset:CGPointMake(0, 0)];
}
-(void)setLandscape {
// set the proper scroll view size...
CGRect navigationBarFrame = self.navigationController.navigationBar.frame;
CGRect detailWindowFrame = splitView.detailViewController.view.frame;
CGRect sframe = CGRectZero;
sframe.origin = CGPointMake(10, 10 + navigationBarFrame.size.height);
sframe.size = CGSizeMake(detailWindowFrame.size.width - 20, detailWindowFrame.size.height - 20);
[self.scrollView setFrame:sframe];
[detailDescriptionLabel setFrame:CGRectMake(0, 0, sframe.size.width, sframe.size.height)];
[detailDescriptionLabel sizeToFit];
}
Right now the application will only display in landscape and the setPortrait function is not called.
This has been driving me crazy for a few hours now..... Any ideas?
I think you need to set the bounds origin of the content view, not the frame. (That's how it works for NSScrollView, anyway.)

frame size of detail view of splitviewcontroller does not change up in ios4.2

I am implementing splitviewcontroller with two views master view and detail view in my ipad application. On changing the orientation of ipad from portrait to landscape I am need to hide the master view and change the detail view's frame size to show up on full screen. For this I am using this code.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
//adjust master view
UIViewController *master = [self.splitViewController.viewControllers objectAtIndex:0];
UIViewController *detail = [self.splitViewController.viewControllers objectAtIndex:1];
CGRect t = master.view.frame;
t.size.width = 0;
t.size.height = 0;
t.origin.x = 0;
t.origin.y = 0;
[master.view setHidden:YES];
[master.view setFrame:t];
//adjust detail view
CGRect f = detail.view.frame;
f.size.width = 1004;
f.size.height = 768;
f.origin.x = 0;
f.origin.y = 0;
[detail.view setFrame:f];
}
This code works exactly fine on ios3.2 but does not work for ios4.2. The master view gets hidden in ios4.2 but detail view's frame size does not change.
Please help me.
Thanks
Shruti
The alternative that I found to my problem is that instead of hiding the master view and changing the frame size of detail view on rotation I just presented the class containing the detail view as the modal view. Earlier I was pushing it from the previous class. I also added a navigation bar to it with a done button to dismiss the modal view. This thing worked for me.
ListingViewController *viewController = [[ListingViewController alloc] initWithNibName:#"ListingViewController" bundle:[NSBundle mainBundle]];
UINavigationController *modalVC = [[UINavigationController alloc]initWithRootViewController:viewController]; // to add navigation bar
modalVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
[self.navigationController presentModalViewController:modalVC animated:YES];
[modalVC release];
[viewController release];