How to set AutoLayouts for UICollectionView and Collectionview cell Programatically? - ios7

i am using collection view in my project which was taken programmatically,it's working fine with iphone 5 but to support for later versions of iphone (iphone6,6+) i am getting trouble .
Thanks in Advance

You might have added the collection view with a specific frame compatible for iPhone 5. In my opinion it is easy to do this directly on the xib/ storyboard directly, else you can add constraints programmatically as well.
Check this link
Swift | Adding constraints programmatically

Related

Problems with UICollectionView on IO9 if It is embedded in a table view

Since my move to the new iOS9 and Xcode 7 I have faced a problem with one of the UICollectionViewin my app,
If I use it as Nib( .xib ) file, it works fine,
but if I embed it in a Table View, the Collection view cell starts way before the first index.
I use a custom layout only for the snapping effect ,and then I let the flow layout handle the rest.
I have recreated the issue in a sample project and uploaded it to Dropbox, here is the link : https://www.dropbox.com/sh/kqsobmg86z3pnhz/AAB52JnPgp1WflJsxqOJHEcZa?dl=0
After doing some research I found the solution:
In the custom UICollectionViewCell class I override didMoveToSuperView()
method to add this:
self.setNeedLayout()
self.layoutfNeeded()
and everything works fine.

ios 7 - transparency in IB not working correctly? setting transparency programmatically also isn't working?

I have created two UIViewControllers in IB.
PROBLEM 1: I can't make the 2. VC transparent.
I have read a lot of stackOverFlow solutions but nothing seems to work in my case.
I have tried the following setup in IB both in my current project and in this simple project and something strange occurs (IB,for 2.VC):
Setting the alpha value below 0,5
Setting opaque to "checked"
Setting the background color to "black"
https://imageshack.com/i/kqdXWk9Jp
The second VC gets pushed when I click "GO TO NEXT VC" (push or modally , doesn't matter) and while he is being pushed I see the the result I want:
https://imageshack.com/i/idXUCFCPp
... and when the push is finished the new VC changes from being transparent to black (not transparent):
https://imageshack.com/i/iqmLw8D1p
I have no clue why this is happening and I cant get it to stop working like that.
Q1: Why is this happening?
Q2: Why can't I change the properties of the views programmatically when the views are created with IB?
I have done this thousand times WITHOUT using IB. As soon as I start using IB things don't work like they are supposed especially when I try to edit stuff programmatically.
When I do all of these steps without IB only in code everything works perfectly fine but I need to use the IB in my next project. I am using Xcode 5.1.1. on mac mini (late 2009) with Mavericks.
Sorry for bad English.
Your problem is because the memory management of iOS removes the previous interface ViewController, to save resources.
After iOS7, you can customize the transition viewControllers. Please read: UIViewControllerAnimatedTransitioning Protocol Reference.
I also had the same problem and managed to solve it by following the tutorial Custom UIViewController Transitions.
If you are still having doubts, there is another tutorial to help you: iOS7: Custom Transitions.
Hope you get success!

Create custom animated segue with images?

I am trying to build a custom segue for an iOS app that utilizes images on the top and bottom of the screen (like a header and footer) that will slide up/down (out), transition to the next page, then slide back in. I found a simple tutorial that does the animation that I would like to use, but I am stuck trying to implement it into a segue.
Is this possible? If so, how? I have barely found any documentation on what I would like to do, and I am royally stuck!
Thanks in advance.
Animation tutorial: http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial
iOS 7
What you're asking about is possible with new APIs. However, iOS 7 is currently under NDA. Please avoid asking iOS 7 related questions on Stack Overflow until the SDK, Toolchain, and OS go final. Ask this question on the iOS Developer Forums. When iOS 7 becomes public, I'll edit this answer to describe how to do it.
Meanwhile (since you're a registered developer), I can point you to a few resources that may be of interest (you may need to sign in to access them).
WWDC Videos
The video titled Building User Interfaces for iOS 7 introduces the new Segue animations and techniques. The part of interest is around the 18:30 minute mark.
The video titled Custom Transitions using View Controllers goes in depth to explain the new custom animated segues and how to use them.
Creating Custom Segues - Pre-release documentation
Posts about Segue's on the Dev Forums - Just search the Developer Forums
iOS 5 - 6
Creating custom segues in earlier versions of iOS (5.0 and up) is fairly straightforward, unlike iOS 7 - the animations can't really interact with views within your ViewController and they aren't as dynamic.
To setup a custom segue, you'll need to first create a subclass of uistoryboardsegue (Documentation Here). Override the perform method and add your own animation and drawing code:
- (void)perform {
//Add your own animation code here, then present the View Controller using that custom animation
[[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO];
}
Now that you've subclassed UIStoryboardSegue and created your own animation, you'll need to connect the segue in Interface Builder.
Create the Segue by Control-Dragging from the source view controller to the destination view controller.
Select custom from the list
Name the Segue by setting its Identifier (this way you can also call the segue using the performSegueWithIdentifier:sender:) method. Then set the Segue Class to the name of your UIStoryboardSegue subclass.

How do I add a new view to a single view application in Xcode

I started my app as a single view application. I have the view with various buttons and labels connected to code. I want to add a button that links to another view.
I found a tutorial that guided me to click on the project and add a UIView subclass. However there is no option for that ( I think because I started it as a single view application).
I'm pretty new to all this so if anyone can outline a simple way for me to do this that would be great! I am using Xcode version 4.3.2.
Thanks!
You need to add a new Objective C class. Please refer to this:
How to create new View Controllers in XCode 4.3
If you started the app as single view using xib file the to add a class just go to name of the project on the left pane and right click on it. Then choose add new file. The pop up will appear to allow you to choose what type of class you want to add. Depending to what the new view is you can choose uiview controller or uitableview controller and so on. Just make sure you check mark with xib for interface user. That should do it. Hope it helps.
Adrian

Working with storyboards in Xcode, how to handle massive Storyboard in iOS

I have been using the storyboard to make an application and currently there are many segues and several components. This is causing a ton of lag when I try to do anything inside the storyboard. Is there a way to hide components inside the storyboard? thanks.
+1, For the potentially features to improve Xcode. Now, there is no way you can hide those views (Not that I know). But I would suggest you to,
Hide the debug areas you don't need.
Hide the document outline while working with segues.
Why?
I think in this way whenever you are making changes, system does not have to repaint those unwanted views and long document outline. Probably this will be less laggy(I don't think there is a word like this)!
Work around
Divide your segue into different meta segues and then you can call those segues from your main segue. In that way you don't have to put each connection on one file but you condense it!
And here we go the documentation for it! Now you can get the story board by different file and then initiate with the UIViewController easily. Then you can just use old ways to segue between different ViewControllers.
Apple Documentation for UIStoryboard
Demo App.
In order to achieve this, I have made a quick demo application which will help any future visitors.
https://github.com/Krutarth/LargeStoryboardManagement
Visually something like this,
You can split one huge storyboard into multiple small storyboards.
Select the view controllers that you want to move to a smaller storyboard, then
In the top menu, click Editor -> Refactor to Storyboard
Save the new storyboard with the desired name. XCode will auto generate all the required storyboard links from your large storyboard to this newly created small one.