What I'm basically doing is presenting a UIActionSheet using showFromBarButtonItem from a UIBarButtonItem in a UINavigationBar in an iPad app. What this does is present the UIActionSheet in a popover, which is what I wanted.
What I would like to do is change the background color of said popover from the default blue to one of my own. Is there a simple app store safe way to accomplish this short of rolling my own custom UIActionSheet in a popover solution?
Not really, because you don't get official access to any parts of the underlying UIPopoverController or its content view controller, let alone the view. On the other hand, as you imply, constructing your own view controller and view is pretty trivial.
It would be quite easy to create your own view with behavior similar to UIActionSheet
Here's an example: http://iosdevtricks.blogspot.com/2013/04/ipad-style-action-sheet-for-iphone.html
Related
How can I present a UINavigationController with navigation bar like a popover on iPhone using custom UIViewController transitions introduced in iOS 7?
I accomplished this with a standard UIViewController and transition animator:
http://www.bytolution.com/Screenshot%202013.11.02%2015.25.34.png
When trying the same with UINavigationController instead, this is the result:
http://bytolution.com/Screenshot%202013.11.02%2015.27.10.png
At WWDC session 218 (login required) an Apple engineer made a demo of the exact thing I am trying to achieve:
http://bytolution.com/Screen%20Shot%202013-11-03%20at%2013.50.17.png
Unfortunately I could not find the sample code anywhere.
If you want to take a look at my code visit Github.com/bytolution/Apsiape
Thanks in advance!
I would take a look at WYPopoperController which does what you want on iPhone: https://github.com/nicolaschengdev/WYPopoverController
iPhone does not support the UIPopoverController class and all Modal transitions are full screen. Yet obviously the screen shot you showed exists.
Any view controller can have its view extracted and shown within another view. That is what's been done there. A black view is placed over the background with 30% opacity and the "popover" view is added on top of that. For added effect, a tap gesture recognized can be added to the black masking view to dismiss the popover when the user taps off of it.
I finally figured out how to do it on my own. I refined my Google search and found the trick to be an embedded UINavigationController. This was also useful for custom view controller transitions as it works nicely. You might want to check out this stackoverflow.com question.
If you need the code, it's in my project on GitHub.
Currently, I'm using presentPopoverFromRect:inView:permittedArrowDirections:animated: to present my popover. But I'm looking for more fanciful animations (eg. the popover expanding from a particular point) to present the popover.
I've tried searching with keywords ios present popover animation but can't find any useful results. Not sure if I'm using the wrong keywords or it is impossible to present popovers with animations.
When using a UIPopover, there is currently no easy way to present it with a different animation than the one that iOS provides. It would definitely be possible to do a custom animation to present a view, but it would be a very significant amount of extra work as you would have to do everything yourself. Two things you could look at if you really, really need to:
UIView animation. Links: Ray Wenderlich tutorial, Apple documentation (search the page for "animation").
Core Animation custom transitions.
As of iOS 7.0 it is possible to present any view controller so that it does not completely obscure the previous view controller, making it possible to create "fake" popovers. Using the UIViewControllerTransitioningDelegate protocol you can then create any animation you would like.
Here is a good example of how to create a fake popover with a custom animation.
I am creating a tableView on my iPad app where one of the cells has a UIButton titled "Edit notes". I would like a view to pop up over the screen containing a "textfield" and the keyboard, not a new view/push. Prefferably not even covering the whole screen. I guess I am looking for the view used when you have your iPad in landscape mode and you compose a new e-mail. A view popping up from beneath while you can still see the main view in the background.
I've been looking around, but I have no clue what to search for!
Here's an image of something like what I'm talking about, only I would need it to say "Save" instead of "Send" and without the "to/Cc/subject"-fields, and I guess I would require an NSString as return value. Any clues?
Or something similar!
This is called modal presentation style.
You can present any UIViewController or its subclasses.
Set the modalPresentationStyleproperty to UIModalPresentationFormSheetand present this viewController from an parent viewController (your tableViewController perhaps) with the presentViewController:animated:completition: method.
Take a look at the docs.
In Interface Builder, search for an object called "Container View". You can include whatever you want in this container and show/hide it when you need.
Just trying to teach myself storyboarding and have run into a question I was hoping people may have an answer to.
I wanted to create a reusable upper toolbar so that in case I ever had to change it, it would update all of my scenes. I created a sized ViewController in my storyboard. I then load it into a subview of each of my scenes using the menu's identifier. THat seems to work pretty well (although, feel free to tell me that's the wrong way to do it).
Here's where the problem starts. On that top toolbar, I have a UIButton which I connect to another sized ViewController in my storyboard as a popover. Basically, a drop down menu. If I just load up the top toolbar, works fine. If I connect just a regular button to that popover scene using a segue, that works too. If, however, I try to click the button and follow the segue while the toolbar is within a subView I crash with EXC_BAD_ACCESS. I presume I'm not allowed to spawn a popOver from a subView or follow a segue within a subview? The latter seems wrong since you effectively do that with any UI object.
How else should I handle this?
Thanks!
I'd recommend using a UINavigationController and setting the toolbar to include your UIButton (as a UIBarButtonItem). If you have any trouble "keeping track" of the toolbar or button you can subclass UINavigationController, add the UIButton (or entire toolbar) as a property of the subclass, and access it from any subsequent view through the self.navigationController property (might violate strict OO, but you could use a protocol).
As for the popover, I think you're OK on iPad but not on iPhone. There are custom projects on github to implement UIPopoverController, and indeed the Facebook app makes use of a custom popover for notifications in their app. iPhone raises an exception if you try to show a UIPopoverController.
Okay, I am still learning how to program and things are moving along quite well, but I have a question for the group about something that has been plaguing me:
How do I create a pop view where the background can still be seen? I mean, say my iPad view has 5 buttons on it, and I want a small square to pop up over where that button was, asking the user a question - how would i do that? Can I make a modal view with an invisible background? (I don't want a UIAlert BTW - I know that would solve my problem, but I am trying to learn how to do this with my own view)
Can anyone point me in the right direction?
You say "pop view" which makes me think you're describing a popover. Have you read the iPad Programming Guide, specifically, the section "Creating and Presenting a Popover"? It really is required reading in this case.
Are you showing the popover from a bar button? If so, you'll want to use presentPopoverFromBarButtonItem:permittedArrowDirections:animated:. If not, you'll need to identify a CGRect that represents the button (you can use its bounds), and then use presentPopoverFromRect:inView:permittedArrowDirections:animated:.
You do not want to obscure the button with the popover. When you show the popover using the above methods, the framework will take care of positioning the popover on-screen. Use the UIPopoverArrowDirectionAny for directions whenever possible.
If you actually want to show a modal view, you can create whatever view you want and then display it in such a way that the background is not fully obscured. Just set the modalPresentationStyle of the view controller to something like UIModalPresentationPageSheet.
You should create a custom UIView with the dimensions and content that you want to display. Then, you can place the custom UIView on screen by calling something like:
//where 'self' is the view controller currently visible and 'customView' is
//the view which has the question for the user. Don't forget to set the
//frame property on customView so that it knows the correct place to display.
[self.view addSubview:customView];
Hope this helps. Andrew