Changing background in iOS - ios

Hey, I have a UIImageView in my app. And I I have 4 backgrounds created for the app. I want the user to be able to change between these 4 backgrounds. I found a video on youtube to give you an idea of where I'm going.
http://www.youtube.com/watch?v=WO9NRIHU6oQ
The user clicks on a button which open a new view allowing the user to scroll thru the backgrounds and when the user got finds the backround he or she wants the user taps on a button again to use it.
Any Ideas of how I would do this?

Seems like it could be done with a parent view controller containing a button and an imageview. The button causes a secondary view to animate up. The secondary view then has theoretically any number of imageviews (but maybe just three, a previous, a current and a next which are dynamically refreshed from an array of images). Then you just have to sync the current imageview contents with the contents of the imageview in the first view in your parent view controller.
I realize a pile of text like this is probably hard to follow, especially if you're new to iPhone programming, but do some reading into uiview and viewcontroller hierarchies and you should be able to figure something out.

Related

How to use CoreData with two view controllers one of them has collection view

First of all, I am new in coding, so please be patient with me.
My app has two view controller, the first has UICollectionView and the second has UITextField.
I am trying to tap on one of these collection view cells and then it takes me to the second view controller, where I can type in the textView then save it into CoreData. And then when I go back and press on the same cell i get my saved text. Then when i change this text on the ui text view.. it saved automatically.
Can any one give me an example or put me in the right track
The essence of how that might be done is to implement the collectionview delegate and then determine which cell they clicked on, so that the next screen loads/and updates the correct data. After they click you would call the "segue" with some code. The segues are setup in Xcode's visual editor by control click and dragging a line to the second view. (It's weird, there are some great youtube videos out there) The data would be stored in an array. After you update the data, you could dismiss the second view and the collectionview behind it would be visible again.
I would check out chapter 4.5 of the free iBook "App Development with Swift". Chapters 4.5-4.8 would really get your rocking the right path. If that book is too complex then also look into "Intro to App Development with Swift"
I even have some videos to take you through the process, dunno if I have one for 4.5 but if you continue with it, I have one for 4.6.
https://www.youtube.com/watch?v=Q5u9SGhQoPY&t=2254s

Should I use UIImageview or something else?

I'm starting an App that will display an image and users will click a "yes" or "no" button if they like it. Then once they decide, a new image will appear and the process will repeat. They will not need to go back to previously viewed images.
My question is would you use UIImageview to do this and would you use some kind of array etc.. or what? Also how would you hook in the yes, no, and next buttons to this type of layout. Would you use a pop up for the "next" button or have it appear somehow in the view etc.. the yes and no would be fixed in place.
The images they say yes to, will appear on another view in a sort of folder.
This is only my second app. The first one I started on wobbly ground, so I'm trying to get some sold feedback before I build the foundation. If you have sample code that would be cool but not necessary at this point.
Thanks!
If you are showing only one image on the page then it is feasible to use one UIImageView and an array of images. When user wants to view next image same UIImageView control will be reused with different image.
The images can be shown in webview also but imageview is ok too. Better keep the yes and no button below the view for simplicity. To populate the imageview you use array of images and on clicking next button or whatever, you can load the next image in the array to image view.

How to create UIView like IMDB app

I'm trying to recreate a view.
I've seen in the IMDB app and have no idea how to do the same thing.
I'm fairly new at app building, so any advice would help.
In the IMDB app when you select pics of an actor, you get a grid view of photos.
If you tap one, it goes full screen.
If you tap full screen pic, 2 semi-transparent bars appear at top and bottom overlapping photo.
These bars contain buttons and text.
How would I recreate this in my own app? Is it a special view? Modal views I know appear from bottom and fill whole screen.
Can anyone help me?
This question is far too vague, you need to attempt this and post more specific questions as you run into problems, but here's some high-level insight to get you started: (Mind you, I haven't seen the IMDB app)
A grid view of photos could be done with a UITableView or a UICollectionView (either in a full size view controller, or placed into a UIPopoverController for iPad), and when someone taps on one you could launch a new view controller that consists of simply a UIImageView filling the screen (you could do this as a full-screen modal). In any case, this view will need to have 2 views (with backgrounds set to alpha < 1.0) which will contain your buttons and text. You will set those views to hidden until the user taps on the full screen image (which you can use a UITapGestureRecognizer for).
Take a whack at it yourself, and when you run into specific issues, post them here and the fine knowledgable people here at SO will be glad to help you.
You can show a modal view without having them come up from the bottom. pushViewController:animated:(if you're using a UINavigationController),presentModalViewController:animated:,presentViewController: animated:completion: all have a BOOL option to turn animated on or off. They probably just turned the animation off.

UICollectionView for Springboard like folders

I am trying to achieve the following effect:
A UICollectionView displays a grid of cells for a parent type of object, e. g. a photo album. When I tap one of these items, I would like to scroll that element to the top of the screen and open a Springboard like folder from it. Inside that folders area, another collection should be shown, consisting of the detail items, i. e. the individual photos of that album. Tapping in the remaining "parent" view closes the folder again. See this schema:
What I have done so far is a regular collection view for the albums. When I select one, it scrolls to selected item to the top and then uses JWFolders to open an empty folder at that place. Once that is shown, I trigger the surrounding UINavigationController to push my 2nd view controller with the detail items. That one is layed out so it appears to the user as if it were still the same view.
There are several problems with this approach, and I would like to know how to do this better:
JWFolders takes a screenshot and animated two halves of it up/downwards to achieve the opening effect. This is ok, but pretty slow on an iPad3, because it moves a lot of pixels and the iPad3's GPU is not quite up to the task.
The 2nd view needs to be pixel-perfect to match on top of the first one. This is likely to break accidentally.
I am limited as to what animations are possible for the view controller transition. The default UINavigationController's push from the right is not fitting. I override that to do a cross-dissolve, but still it is far from ideal.
I would like to get pointers as to how to approach this problem in a maintainable manner that does not require to much creative hacking against what the frameworks are designed to do. I might be missing something obvious here, so pointers to examples or general advice are appreciated.
Update:
I changed the approach a bit. Now I use a container view controller that has two embedded collection view controllers. One for the "Album" and one for the "Photos" part at the bottom. Using a UIImageView in the middle between the two I can get the triangle pointing upward done. This is also nice from a maintenance point of view, because it makes maintenance easier with the two collections being handled completely separately.
The app uses Auto Layout, so I can change the amount of space each of the two embedded views takes by modifying the constraints. This is way faster than the screenshot based approach with JWFolders and works nicely on an iPad3 as well.
This almost gets me where I want to be. The one thing that remains is to get the opening animation right. I would like to simultaneously scroll the Albums collection, so that the tapped item goes to the top and expand the photos collection with the triangle pointing at the Album cell.
Can I somehow "connect" the lower view to that cell via layout constraints, so that the scrollToItemAtIndexPath:atScrollPosition:animated: call drags the lower view open?
To get around it I would lose the library and cause iOS to move those display elements around without screenshots or other tricks. On the tap, cause the tapped icon to retain its normal appearance while you dim all the others. Find the contents of the collection view from the top to the end of the line where the tapped icon is. Create two new collection views - one which contains the top half, including your tapped icon and one containing the rest, below. Animate those views apart to make room for the folder view.
The folder view is another UICollectionView that appears in the gap created.
In the main view there are either one or three views presented depending on whether the drawer is open or closed. I would probably look at creating a view controller with a collection view, and using view controller containment to manage all three views. You have complete control over how those views are presented, so you could animate top and bottom views up and down simultaneously to reveal the folder view in place, as Springboard does.
When that's all working then you could generalize and start doing things like deciding to make the tapped icon part of the bottom collection with the folder appearing above if the icon was low on the screen.
(I hesitate to answer this because of the large number of upvotes yet no answers, so I may have missed something - but that is how I would begin trying to achieve the Springboard effect.)
To solve this problem in a relatively easy way, you could try to make the folder a simple UICollectionView subclass and then insert that cell when the albums cell is tapped.
In the collection views data source you would have to return different size etc. for the folder cell.
In the folder you would have to create the folders collection view, avoid making the folder cell the data source of the cell folder collection view tho.

Automatically scroll to a subview in a scrollview

I have implemented a scrollview that has dynamic content: multiple sub-views displaying photos of players with player names under. The flow is:
1. On the main window, a player is selected.
2. User launches another view to add a new player.
3. When the user goes back to the main menu, the scroll view is refreshed completely so that the new player photo and name is also displayed.
At this time, the scroll-view should still have the previously selected player in focus but instead it is showing it from the beginning.
So the question is: is there a method to automatically scroll to a specific position in the scrollview so the screen still has the selected player in focus?
Yes, there are two:
(1) scrollRectToVisible:animated:
(2) setContentOffset:animated:
You can read about both methods at UIScrollView Class Reference. Either way, you can use an instance variable to store the content offset or the visible rect when the user scrolls, and then use one of the methods I listed above to restore the scroll view position when the player data is updated.
Depending on what you are doing, you may find UITableView easier to implement because it is very customizable "out-of-the-box" and it has plenty of methods to help manage a list (including the ones I mentioned above, and more). If you're interested, have a look at UITableView Class Reference.
Simple, create a CGPoint and a BOOL that you can retain after the view change and set them when you initially navigate away from that page. Then in viewDidAppear you can check if the BOOL is YES and use:
[myScrollView setContentOffset:myCGPoint animated:YES];
Or, if you want the scroll view to appear already scrolled to the correct position, do the same thing except in viewWillAppear with the animated flag set to NO.

Resources