Present Modal View in iOS 6 - ios6

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

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.

How to stop animation flickering

Are there some generic techniques for stopping the display flickering? I'm guessing that I have two layout animations that are fighting over the controls or something - this seems to happen in a few places in my app (hence the general question).
I'll try and be more specific too:
I have a Box Layout Y Container which contains a list of MultiButtons. The MultiButtons are my own class which inherits MultiButton. It (all the buttons) flicks when I come back to the Form from another form. In the beforeForm function I do this:
for (my loop)
{
MultiButton mb = new MultiButton();
...init code for mb, like setTextLine1();
container.addComponent(mb);
lastMb = mb;
}
container.revalidate();
container.scrollComponentToVisible(lastMb);
The beforeForm method is invoked before the form is shown so there is no need to revalidate at that stage (show implicitly does that).
What's scrollToComponent? If you remove it does it flicker?
To scroll to a component without an animation do:
container.setSmoothScrolling(false);
container.scrollComponentToVisible(cmp);
container.setSmoothScrolling(true);

Slider in codenameone

Can any one please tell me how i can add slider and moving form in codename one (with sample lines of code) and also want to know are these features supported by all types of devices?
Regards,
Megha
I think you mean how to animate forms changes
Form.setTransitionInAnimator(CommonTransitions.somthing)
Form.setTransitionOutAnimator(CommonTransitions.somthing)
Next, you should handle some "finger slide" event.
To add a slider you can use the following code
Slider jSlider = new Slider();
jSlider.setMaxValue(255);
jSlider.setMinValue(0);
jSlider.setProgress(50); // Set the starting value
jSlider.setEditable(true); // To it works as a slider instead of a progress bar
Now you have created a slider which you can add to your component like you would in Swing. You can type 'jSlider.' in eclipse to find out which other methods you can use, or you can go to the API: http://codenameone.googlecode.com/svn/trunk/CodenameOne/javadoc/com/codename1/ui/Slider.html
I think min/maxValue are selfexplenatory though :)
If you want to open a new form, simply create a new class extending form or do it in code like
Form form = new Form();
form.animate(); // To make it "slide in"
form.show();
Also noteworthy, the slider doesn't work with the lumia skin per default, though you can make it work. I actually asked this question on here as well:
Slider doesn't draw (CodeName One) with Windows phone skin

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

Custom Segue with CollectionView for iPad

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.

Resources