This code presents my new view controller, but it comes in from the right instead of up from the bottom. I can't figure out how to get it to do a vertical animation. Any thoughts?
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:newDeal];
navigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:navigationController animated:YES completion: nil];
I found it - my segue was set to "Push" and not "Modal". Once I set the style to Modal and the transition to "Cover Vertical" it worked perfectly.
Related
I have an app that changes the contents of a table view cell when the user taps a button in that cell. If the cell is partially visible at the bottom of the screen, I have an animation move the table view up to display the entire cell (then move it back when done). On iOS 7, everything is fine. But on iOS 6, the shifted cell consists only of what was visible before the shift; anything that was 'hidden' behind the tab bar is blank white. I've tried calling [self.view setNeedsDisplay], and even [self.view performSelector: #selector(setNeedsDisplay) withObject: nil afterDelay: 0.5], but it still doesn't redraw correctly.
I overrode -drawRect: in the table view cell class, calling [super drawRect: rect] and set a breakpoint there, and that runs before the animation happens.
How can I get the redraw to take place after the animation?
In the custom UITableViewController:
- (void) shiftTable: (CGFloat) distance
{
[UIView beginAnimations: #"TableShift" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: 0.35];
self.view.frame = CGRectOffset(self.view.frame, 0, distance);
[UIView commitAnimations];
}
I figured out the issue:
Shifting the view via an animation like that doesn't reveal any more data. The line where it clipped the visible data is in the same position relative to the cell, and the cell is in the same position relative to the view. On iOS 7, where it draws the table view behind the translucent tab bar, the data is already there (but obscured), so when it shifts, it reveals that data. In iOS 6, the tab bar is not translucent, so the table view stops at the top edge of the tab bar. When the animation moves the view, it moves the clipped view up.
The solution is to scroll the table view, rather than just move the view:
CGRect cellRect = [self.tableView convertRect: cell.frame toView: self.tableView.superview];
CGRect tableRect = self.tableView.frame;
if (cellRect.origin.y < tableRect.origin.y)
{
[self.tableView scrollToRowAtIndexPath: cell.indexPath
atScrollPosition: UITableViewScrollPositionTop animated: YES];
}
else if (cellRect.origin.y + cellRect.size.height >
tableRect.origin.y + tableRect.size.height)
{
[self.tableView scrollToRowAtIndexPath: cell.indexPath
atScrollPosition: UITableViewScrollPositionBottom animated: YES];
}
so I created my own custom layouts for my UICollectionView. When i rotate from portrait to landscape mode, some of the cells start to reload its content. I thought the layout just changes the positions of every cell not reload the content?
The content should only reload when i call reload Data on the collection view.
Any ideas to what might be going on?
Use invalidateLayout instead of reloadData on rotation, or override shouldInvalidateLayoutForBoundsChange: and return YES in your UICollectionViewLayout subclass.
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
myCollectionView.frame = self.view.bounds;
[myCollectionView.collectionViewLayout invalidateLayout];
}
Not sure if you are aiming for this, but here it goes:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[self.collectionView reloadData];
}
I have a setup where an iPad app supports all orientations. In part of the application, a tap triggers the display of a modal view controller which requires a navigation controller. So I'm basically doing:
UIViewController *myViewController = [[UIViewController alloc] initWithNibName:#"MyView" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:myViewController];
NSLog(#"%d", nav.interfaceOrientation);
[window.rootViewController presentModalViewController:nav animated:YES];
This works fine when the iPad is in portrait (home button). In any other orientation, the modal view always appears in portrait from the home button rather than the current bottom of the device.
If I skip the navigation controller completely and just show myViewController modally, it appears correctly.
So, I tried subclassing the UINavigationViewController and explicitly overriding the shouldAutorotate: and supportedInterfaceOrientations: methods, but this doesn't have any effect. Interestingly if I override the viewWillAppear method and log the value of the interfaceOrientation property, this always returns 1 even if it returns the correct value when accessing it from the code above.
I've also checked that all orientations are supported in Info.plist.
So, what else could be happening to cause this behaviour? Any help greatly appreciated.
Try to implement preferredInterfaceOrientationForPresentation in your subclass of the navigation controller.
The following worked for me:
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return self.interfaceOrientation;
}
I have an iPad App I am working on. I have a UICollectionViewController with images displayed in the Cell.
On the MainViewController I placed a ContainerView that segues to a UIViewController that has a UIImageView.
This all (Above) works fine.
I want to set things up so I have a Custom Segue from the CellViewController to the UIViewController housing the UIImageView. I want this UIImageView to change based on the Image I select from the Cells displayed in the CollectionView
Can I create a Custom Segue to do this? I can't get any of the other segues to work because they are for SplitViews or Popovers, or Pushes.
I want to display a modal view but I have two problems:
There is no presentModalViewController in iOS 6 and I have to use presentViewController which is just display my second ViewController like a modal segue not a modal window without full screen option,
My second problem is how can I show the modal window from UICollectionViewController. I tried to use presentViewController but it just works with ViewController not CollectionViewController.
The best example of what I want to do is this (Instagram). How they made this modal window? Is it because it's still working with older iOS versions and it's not iOS 6 yet? Or there is another way to display modal window like this from UICollectionViewController?
Thanks
If I understood you correctly what you are trying to achieve is to present one of your ViewControllers over the parent and still see the parent ViewController in the background.
First solution:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext; //self.modalPresentationStyle might do a better job here
[self presentViewController:vc animated:NO completion:nil];
Make sure your SecondViewController content is smaller than your current ``ViewController` and that you can see the background color of it in StoryBoard \ xib. The background color will be clear and will create the transparency effect.
Second Solution:
Create a Container (iOS 6 and up if you are planning to use the Storyboard IB, lower than that will let you create Containers but only progrematicly).
Set the container size 3/4 of the parent size and connect the second viewcontroller to it. Instead of segueing \ pushing to your second viewcontroller you can just
myContainer.alpha = 1;
to show it on screen.
I would take a look at the docs for UIContainerView which is used for displaying a view controller as a child of another view controller in a similar way to a non-fullscreen modal presentation.
As you are saying that presentViewController is only works with UIViewController not UICollectionViewController.
Then simply import UIViewController class in header file of CollectionViewController as displayed below:
#import <UIKit/UIKit.h>
#class UIViewController;
#interface MyCVController : UICollectionViewController
#end