When should a UIView be placed over the current views (in the same controller) vs adding a whole new UIViewController?
I know that the UIViewController manages UIViews, but imagine that you wanted something to popup when a user selected something. What decides whether a UIView be animated and added to the current controller (using animateWithDuration), or a new UIViewController with a custom transition?
Twitter example:
http://i.giphy.com/3o7TKKcmcIz76ONXFe.gif - Not sure if this is a UIView added to the existing controller, or if it's a new controller. I just tap the image, and it pops up. I then slide down and slowly move the image off the screen (interactively).
Spotify examples:
http://i.giphy.com/3oz8xRSkmxbcVqPZf2.gif - Probably a UIViewController. I'm grabbing the bottom bar and sliding it up. I then slide down on the album cover.
http://i.giphy.com/3oriO7SjzB5GfThx60.gif - Possibly a UIView? Happens when I press and hold a album cover.
What determines when one should be used over the other? It would probably be helpful if you explained the examples. Thanks.
Related
There's a particular control which I'm trying to build properly. I refer to it as an ImageTile. It's basically a little square box, which, when the user taps it, will present the user (via an action sheet in a popover) the option of selecting an image from the library, or taking a photo. Depending on the response, I then either present the UIImagePickerController inside a popover (for selecting an image) or modally (for taking a new picture). Once they take/select the image, I have a modal view which appears and allows them to edit the picture in a few simple ways. When they finish editing, the modal dismisses, and the original ImageTile, rather than being a blank square box, gets filled up with the user's edited image.
The issue is that this ImageTile control is going to be used profusely throughout several different parts of the application, across numerous View Controller hierarchies, and so on... and I really want it to be a basically totally self-contained unit, such that whenever I stick an ImageTile inside a UIView onscreen, all the above functionality is handled by the ImageTile itself.
Initially, I made it a UIViewController subclass (so it could present modals etc), and just added its view as a subview of a "holder" view onscreen. I know this isn't recommended, as the controller isn't part of the VC hierarchy then... and also, I wound up with some really weird behavior regarding things like autorotation, especially when the camera was involved.
What's the "right" way to implement something like this?
I think what you've done by making it a UIViewController subclass is correct. You should just use the methods that UIViewController exposes for adding child view controllers, such as - addChildViewController:.
You will also note that Interface Builder has a Container View object designed specifically for holding a place in the hierarchy for a child View Controller:
Apologies if this seems a straightforward question! I'm using AVFoundation to build a custom camera app that allows the user to draw on the image after it's taken (similar to snapchat).
I have the camera functionality working. Currently, after the shutter button is pressed I add (as a subview) a standard UIImageView to display the photo taken. Seeing as I want there to be custom options at this stage (including drawing on the image), I proceeded to create my own subclass of UIImageView. I am designing this view in Interface Builder (xib file).
Say for instance I have a button on this custom view, that when pressed, simply deletes the image and takes me back to the camera view to take another image. Can I handle the IBActions for this custom view within the ViewController for my camera view? Is this bad practice?
Any guidance on how best to implement this would be really appreciated! Thanks.
I would not suggest putting the button on your custom view.
I would have the UIViewController display the custom view and also give display a button for your action. Most likely the UIViewController will want to display a UIToolBar at the bottom of the screen which will allow for multiple buttons/actions, but that's up to you.
But why do I say this? Compartmentalization. Your custom view has no need or use for the button. It's meaningless to what your doing... displaying the image. Your custom view will also probably be used in many locations, several of which won't want this button displayed. Even if your custom view had the button it wouldn't know what to do if someone tapped it. It would then have to pass that interaction off the view controller which cares about the action and and handle it. Your custom view will mostly likely have public methods allowing other code to give it directions (like clear or undo).
Depending on the say things go, you may decide you want a custom UIViewController which handles interactions on your custom view. Then any other view controllers could just add it in as a containerized view controller and you could have the same functionality with no code duplication at several places in your applications.
I need to show UIVIew when i will swipeup on UIViewController in ios with animation like it is coming from that UIVIewController,and i need to place that UIVIew in specific portion in UIVIewController not to cover on entire area.But my problem is i need to create this one in storyboard,normally storyboard means its for showing over all project flow so ,how to do that in storyboard.Please help me as soon as possible.I am new to iphone development i can do by programatically but i am not getting how to do with xib.
Thanks & Regards
Harshitha
You're going to want to look at custom View Controller transitions, introduced in iOS 7. There were a couple of WWDC 2013 sessions on this, including one called "Implementing Engaging UI"
The fact that you're using a storyboard doesn't matter, storyboards are just a way to define your view controllers and navigations via segues. If you're doing a custom animation, your View Controller still segues as normal, it just does so with a custom animation (instead of one of the stock ones, like a Navigation Controller "push" or the various Modal VC presentations), which you provide via an animation controller - an object that conforms to UIViewControllerAnimatedTransitioning.
Storyboard, or XIB? They are different.
The simplest thing to do is probably to create your view and get it set up in it's final position inside the view controller. Hook up an outlet to your view in your view controller.
Note the Y coordinate of the view when it is at the location you want it. Then use the size inspector to change the y coordinate of the view to the bottom of the view. (768 for a landscape iPad app, 1024 for a portrait iPad app, etc.)
Then attach a swipe gesture recognizer to your VC's content view, and in action for the swipe gesture, use a UIView animation method (animateWithDuration:animations: or a similar method to move the view's frame.origin.y up to the y desired y coordinate.
In my current test app I have a UITabBarController, linked to a UINavigationController that leads to a UIViewController with 6 buttons in it and a second UIViewController with a UIImageView. I've created a segue for each button, wich works.
I want to be able to create a swipe pictures feature inside that UIImageView. The source pictures are inside the app's folder.
I'm not sure about your question.
If you need to create a sort of slider of images, you could create a UIViewController with a UIScrollViewas the main view (or as a subview of UIViewController's view).
Once set up, you could create a for-loop where you create UIImageView elements to wrap the image you are loading from your app folder and add each UIImageView to the scroll view.
To make possible to snap photos within the UIScrollView set its property pagingEnabled to YES.
For further info you could take a look at Scrolling sample provided by Apple.
Hope this helps.
I'm developing an iPad application and I need to create an UIView that is always on top in respect to other views.
A is the area (consider it as a sort of sidebar) where I need to create a UIViewController which view remains always on top. B, instead, is the content area where a UIViewController (with its view) can change: depending on several button actions (inside A's view), it's possible to remove the current visible content (in this case controller B and its view) and display other controllers (C, D, E, etc.) with theirs views.
I created all the elements for my application but I have problems to maintain A's view on top and, at the same time, implement the logic used to dinamcally change the content area. As requirements I need that A always overlaps B. In other words, a portion of B (the left part) is always under the area of A. B always extends the entire device screen.
Could you give me some advice?
I made two configurations but I have problem with them.
First Configuration
In the first one, I created an UIViewController for A (called SideBarController). I added SideBarController view to UIWindow (within the application delegate). Then I created an UIViewController for B (called HomeViewController) and I added it as a rootViewController for my application.
This solution could be a valid one because I can change the content area dinamically (setting a new rootViewController) through my application delegate but the SideBarController remains always under the current visble view.
Second Configuration
In the second one, I created an UIViewController (called MainViewController) and I added it as a rootViewController for my application. Then within MainViewController I created an UIViewController for A (called SideBarController) and I added SideBarController view to MainViewController. Then the content area has been filled creating an UIViewController for B (called HomeViewController) and adding it to MainViewController.
The sidebar remains always on top but I have difficulties to change dynamically the content area within MainViewController. How is it possible to access the content area and change it?
Note I'm aware about standard components on UIKit but I need to implements such a solution because of user specifications.
I would begin by trying to implement your sidebar in a UIPopoverController. It's designed pretty well for this kind of problem, and you can customize it extensively to meet your UI needs. If UIPopoverController causes you some kind of problem, I'd put the sidebar in its own UIWindow and float that over the main window.
EDIT
Personally I'd go for the popover myself since it's more built for this kind of issue. Another thought that comes to mind and I've used in the past is a UIView that you add to directly to the UIWindow ([view window] from any view will get you the main one). Remember, UIWindow is just a special kind of UIView. The problem with this and the UIWindow solution is that you will have to do your own rotation logic which can be trickier than it sounds if you have autorotations. UIPopoverController handles all this very cleanly and automatically if you can use it.
If you pursue UIWindow see the Windows section of the View Programming Guide: http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingWindows/CreatingWindows.html