UICollectionView reload cells while rotating - ios6

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];
}

Related

Polymer grid in different views

I'm not sure if this is the right place to ask because I dont have any code to show. I'm actually looking for ideas on possible ways to solve my problem.
I have an app that displays the grid on the screen when the media query has a min width of a tablet.
But when the view is in mobile mode I don't want to show the grid. Instead I have a drop down menu which has a grid option. When selected will be show in a paper-dialog (pop up)
The problem is I have to create two grids (vaadin-grid) and show the appropriate one based on the view. Is there a way to have only one grid? Can I put it in a paper-dialog but not pop-out when in tablet and desktop view?
Thanks in advance
If your grid element has every custom property then that is an element in the DOM, so you can move it into the dialog if thats needed using javascript:
let myGrid = this.$$('#myGrid');
let myDialogContent = this.$$('#myDialogContent');
Polymer.dom(myDialogContent).appendChild(myGrid);
Also if you think it a different way, then you can hide the grid outside of the screen and you can slide that in when it's needed like a drawer panel and you dont need to move the element at all in the DOM.
By the way for programming question stackoverflow has the https://softwareengineering.stackexchange.com/ site, but I think it is Ok to send it here.

NavBar and StatusBar in iOS7 acts strange

If I have an "old" app with a NavBar and build it with iOS7, the StatusBar is visible together with the NavBar and it looks like a mess! And if I have a flip view (TransitionStyleFlipHorizontal), that TopBar is placed below the StatusBar and when turning back the view the window jumps up in an ugly way to cover the StausBar again. Do I have to reconstruct everything from scratch to make it look good. Just to make the StausBar stay on top of the NavBar? It must a simple way to fix that but how?
Write below code in your .m file.
It basically help you to change location of navigation bar.
-(void) viewDidLayoutSubviews
{
CGRect tmpFram = self.navigationController.navigationBar.frame;
tmpFram.origin.y += 20;
self.navigationController.navigationBar.frame = tmpFram;
}

Modal UINavigationController presented in wrong orientation

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;
}

How to dismiss popover before orientation change on iOS 6?

Does anybody has an idea about how could I dismiss a popover before orientation change on iOS 6.
I've tried the following:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:NO];
}
}
But it is not working for me. The popover is still there after the rotation.
- (BOOL) shouldAutoRotate
is not called in my viewController cause it's in a SplitViewController and NavController.
I've read that I can subclass from this containers to forward the shouldAutorotate, but I don't want to do this because of different reasons.
I don't want to dismiss popover after orientationchange (in didRotateFrom...), because it's ugly.
Do you have an idea, how could I dismiss the popover before orientation change on iOS 6?
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(deviceOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
This will do it once the rotation did change then you can do what you want in the device orientation. Otherwise you need to listen on the view controllers and send the message there.
try this
- (void)viewDidLayoutSubviews
{
[popOverController dismissPopoverAnimated:YES];
}

Present Modal View in iOS 6

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

Resources