I have a View Controller (with a UIWebView) i present in Form Sheet style. I have to put a "Done" button in the UIToolbar of the view in the View Controller to have it dismissed. But, since presenting it in "Form Sheet" style leaves plenty of unused space outside the View Controller's view... I was wandering.. Is there a way to detect a touch outside the View? in that "grayed out" area? Thanks in advance
相关问题
- how do you prevent page scroll in textarea on mobi
- Image loads in simulator but not device?
- How to change the backgroundColor for all UITableV
- UIModalTransitionStyleFlipHorizontal flips Vertica
- The bundle identifier cannot be changed from the c
相关文章
- Xcode: Is there a way to change line spacing (UI L
- How do you detect key up / key down events from a
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- How to get a CGImageRef from Context-Drawn Images?
- Why are my UIView layer properties not being set w
- Can I release an app without the device?
- create UIImageView
- How to set different navigationbar color for diffe
On iOS 4.2, the view hierarchy of a Navigation Controller based app with a modal form sheet is as follows during
viewWillAppear:
. Once the modal view appears, the UITransitionView has been replaced by a UIDropShadowView that contains the modal view hierarchy.Apple warn against relying on the subviews of built in views, as these are considered private and may change in future releases. This could potentially break your app.
Approach 1
We can insert a transparent view between the last two subviews of window, and have it respond to touch events by dismissing the modal form.
This implementation checks that the window's view hierarchy is as expected, and will silently do nothing if not.
Create and use
DismissingView
fromviewWillAppear:
in the modal view controller.And the implementation.
Approach 2
The first approach is preferred, as this one has additional logic for every touch event on the modal form.
Add the transparent view as the front view of the window. Touch events within the modal view's frame are passed to it, and those outside the frame dismiss the modal form.
Before it appears, the modal view hierarchy looks like this. When it appears, the UIDropShadowView replaces the UITransitionView in the window's subviews. The UILayoutContainerView
The implementation is mostly the same as before, with a new property and
addToWindow:
replaced byaddToWindow:modalView:
.DismissingView can still be added to the window in
viewWillAppear:
, since the UIDropShadowView replaces the UITransitionView.Again we silently do nothing if the view hierarchy is not as expected.
I think the right answer is, "don't do that"