Disabling user interaction of all views besides one - iphone

I'm trying to simulate a UIAlertView behavior. Basically I want to present a view and disable the user interaction of all other views on screen (besides the presented view). How would I go about doing this?

Your pretend alert view should consist of two views. The first one is the size of the screen and has userInteractionEnabled set to YES. This prevents any touches going through to the views underneath. You then add, as a subview of this view, your actual alert window, with whatever buttons etc. you like.
You can contain both of these in a new UIWindow which you can set the windowLevel on to ensure they are on top of anything else in the screen.
You can also add a very slight backgroundColor to the screen-sized view which will dim everything behind it, if that is appropriate for your interface.

I would recommend adding a view (with user interaction disabled) with black background with an alpha of 0.3 to the applications' main window whenever you show your custom alert. This, in addition to preventing user interaction, also adds that subtle darkening effect to the UI behind your custom alert view.

Call [view setUserInteractionEnabled:NO] on all the views you want user interaction to be disabled. Don't forget to call [view setUserInteractionEnabled:YES]; on them again before you dismiss your custom alert view.

Related

How to tell VoiceOver that a control has animated away?

User taps control and a different view comes up, animated. VoiceOver still highlights the removed control and it is stuck. User can't interact with the view.
This is not in a UIViewController but a custom UIView subclass.
How to tell VoiceOver to update its presentation or state when something appeared or disappeared with animation?
You can post an accessibility notification to indicate that the layout or the full screen of content has changed and select a new element.
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification
elementToSelect);

Disable all superviews except a specific view

I have UIView that open with a UIButton click. I want to disable user interaction of all other superviews except to this specific view and his subviews, how can I do that? Just to make this view the only view that will response to user touch.
Thanks!
Agree with the comment, you probably want to disable all siblings of a view... (edited so you can set them back to enabled at some point)
- (void)setSiblings:(UIView *)view enabled:(BOOL)enabled {
for (UIView *sibling in view.superview.subviews) {
if (sibling != view) sibling.userInteractionEnabled = enabled;
}
}
I know you already accepted an answer but a better (and easier) approach is to display the new view full screen. Make the new view with a clear background. Then add the real view as a subview to this full screen view. This way you don't have to mess with any existing views to display this new view. You can still see everything behind it but touch events are blocked by the clear, fullscreen view.
Then when you remove this full screen view (fade out animation?) you don't have to mess with all the existing views again.
You shouldn't have to modify existing views just to display another. And what happens if one of those existing views really should have its interaction disabled? You will end up enabling the interaction when you dismiss your "modal" view.

How to change UIActionSheet view?

As I observed that UIActionSheet is always appearing from down side in iPhone,
but in some app, as I saw in AlarmClock, then two button became visible, one from upside and second from downside of iPhone,
What is that exactly, I can't understand, as far as I feel, it looks UIActionSheet,
I want such appearance for one of my app....
Help!
Yes just like Ole said, you can't customize UIActionSheet . But since it is just a simple subview you can create your personal "action sheet" by subviewing and animating. So if you want a button to appear on the top and one on the button, then create two UIViews resize them to the right size for your button, add your action sheet style background or any other background, add your button, connect your IBActions to the buttons and your IBOutlets to the views. Then when you want the buttons to appear animate them onto the screen (using sone CGRect, animation time and finally [UIView commitAnimations])
Probably just one or two custom views with a custom animation. UIActionSheet is not customizable so if you want something else than the default behavior you have to write it yourself. It's not that difficult.

Re-add a UIButton

I'm creating a simple matching game for kids for iPad. All images are drawn on buttons.
When a matching pair is found,
[matchedBtn1 removeFromSuperview];1
[matchedBtn2 removeFromSuperview];
Now, I'm creating a reset function which allows player to reset the once he/she is done.
Question is how do I re-add the UIButtons</code>?
Tried this,
[self addSubview:matchBtn1];
But the program crashes once reset button is clicked and gives this warning for every button I addSubview to
"viewController" may not respond to "-addSubview".
Many thanks in advance for your help. :)
try :
[self.view addSubview:matchBtn1];
I think you should be trying to add them to the view of the controller, not the view controller itself.
[[viewController view] addSubView:matchBtn1]; 
Also make sure you have kept a retained copy of matchBtn1 somewhere in your classes as it will have been released when you removed the subviews.
Instead of adding and removing them, create a set of transparent views over the buttons and when you want to remove them, change the color of those views so that the buttons are hidden. That way if you want to reset the screen, you just have to reset all those views to transparent. You may have to set the cover views to intercept touches too, so the user doesn't click hidden buttons.

iPhone UIActionSheet with UISwitch and UITextField

I'm just looking for advice with this as I have no idea where to start but I think a UIActionSheet is probably best.
What I'd like to have is a pop up window (in my head I picture it as being translucent and dark gray). It will not take up the whole screen and the view underneath will still be visible.
In the pop up section there will be a textfield (with several lines) and underneath this there will be a number of UISwitches.
The pop up will be scrollable and will end with OK/Cancel buttons at the bottom.
Like I said, I really have no idea where to start with this but any advice is more than welcome!
A UIActionSheet is probably not what you are after in this case (although you may want a similar look and feel). Think of an action sheet as a traditional modal OK/cancel/Yes/No type dialog box:
Use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task.
From the sound it of it, you need to create a UIView in InterfaceBuilder with a semi-transparent background and various child controls (UISwitches and UITextFields). You create your view using the XIB you have configured and add it as a subview of your UIViewController's view. If you want to mimic the animation you get from an action sheet, you can do that with an AnimationBlock.