Remove UIToolBar from the View - iphone

I have a UIbutton, and when i click on that button i will show UIToolBar (located some where middle of the screen). (i coded this, and it works fine)
Now what i need to do is, when the user clicks anywhere in the screen, this toolbar should disappear. I know how to remove the uitoolbar off the screen as well toolbar.hidden = YES;
The thing i don't know is to remove the uitoolbar when the user clicks anywhere in the screen.
How can i code this ?

Create a full screen view (to be used as container, set its backgroundColor to clearColor), add to this container view another full screen view (which can have a black background color and alpha 0.6) and then add your toolbar to the container view. In that second full screen view add a tapGestureRecognizer and in its selector, perform your animations, where you can do a cool fadeout. Use the completion block of the animation to remove/release anything you have to.

Try setting nil for your UIToolbar. that is set the object value to nil for your toolbar.

Related

How to put my 2 existing buttons to the foreground, they are now behind an imageview

The question is in the title.
There must be a simpel way to do this I guess?
There is an imageview on the screen, there doesn't have to be any interaction with it.
On the imageview I want 2 small buttons left and right but the buttons were created (and the code is written) before the imageview. How do I set this imageview to the background? :)
[self.view sendSubviewToBack:yourImageView];
You can add buttons as subview of imageview.
you can write below code for that:
[imageView addSubview:button1];
[imageView addSubview:button2];
So buttons will be appear in foreground.
When looking at your xib or stoyboard (where you can see the layout), you can use the View Controller scene which is a list of all of the objects, views etc on your Apps layout.
You can click and drag the UI image view so its above the buttons in the list. I'm guessing it's just defaulted to being on top of the buttons.
In your storyboard, choose your viewController by clicking on it. On left side you can see hierarchy like left side view in this image. Check if your imageView is below, in hierarchy, to your 2 buttons. If it is, then drag the imageView and move it above both the buttons.
Concept : The view that is below in hierarchy is visible on top of all the views above it.

How to make my background view to be dark when the another view is showing?

I have an iphone application in which in a button click i am showing a view like an alertview.at that time i want my remaining views (background) to be a shadow one,like as we see the background when showing the alertview.Can anybody help me to achieve this?
This is rather simple, make your new view a sub view of a view that covers the full screen with alpha set to 0.7 or something and the color of your choosing, then present this view and everything behind should be darkened.
You can just alloc a view with the main view's frame, and set the background color to gray, when you click the button, add this view and then add the specified view or you can add the specifed view in this gray view....
You can simply add a UIView as a subview of your controller view. Set black as the backgroundColor of it with an alphaValue between 0 and 1. Remember to set the frame equals to the viewcontroller view
In your alertview callback, just remove the view.
When a button click for showing a view:
-(void)yourButtonAction
{
[self.view setAlpha:0.3];
}
Now when removing view like an alertview.
[self.view setAlpha:1.0];
Best way is to create a new image (black translucent background patch) and add in the background of the superview and set the background color of superview as clearcolor.

Adding a UIToolBar above a UITabBar - Logic Issue

I need to know the logic of how to write this code.
This is my problem.
When a user taps a button, I need to show a UIToolBar (with a few buttons on it) on the view. This toolBar should appear ONLY above the UITabBarcontroller.
The view is a UIScrollView, so if I hardcode the position of the UIToolBar, it will be displayed in the wrong position each time the user scrolls (Hope you understand what I am saying).
I did the following. I hard coded the position of the UIToolBar (so it will place above the tab bar), and added it to the Window. This sounds like a good solution as the windows size will not change at all instance.
But, I don't want to add this to a Window. So is there any other way I could solve this problem?
I would add an additional UIView to the window so that it acts as a container for both the UIScrollView and UIToolbar. Then resize the scrollview so that it falls short of the toolbar.
You should be thinking of this as layers of views

xCode 4.2 iOS5 interfaceBuilder cannot tap on a button that is laid out in the IB

I've ran into a weird issue lately:
I have a 320 x640 UIView within a UIScrollView. I've manually positioned buttons throughout the view and assigned actions to them. One of the buttons has a center at [x,y]: [287,440]. The button is 60x60.
I can tap all other buttons and controls located as low as Y = 353.
I see that the button is located on the same level as all of my other buttons, within the same view as them.
What could be causing my button to be completely untappable? I have another controller, which is also "tall", and there buttons located "off screen" are tappable. [If I move the button up to the level of other buttons, it works as expected.]
Here's the scroll view code:
self.scrollView.contentSize=CGSizeMake(320, 640);
Something is covering it. Try looping over all subviews and printing origin.y relative to scrollview origin.y, and then height plus relative position. Do this in viewWillAppear. Be aware that autoresizing behavior can kick in right after viewDidLoad and fool you. That is what happened to me earlier. There will be an overlap somewhere.
Can post code example later from home if this doesn't get you through it.

iPhone UIButton Parent Frame Changing Touch Up Inside Event Issue

I have a UIButton within a UIView. The button is docked on the bottom of the view using the Autoresizing Masks. The button is working fine when the view initially loads and the IBAction is being called successfully.
Now when I resize the height of the parent view the button stays docked at the bottom of the view, however now only half of the button responds to the touch events. If I resize the parent view height a bit larger then the button completely doesn't respond anymore.
Any ideas why this would be occurring?
It sounds as if you've got another view, most likely a transparent one, that is resizing improperly and covering up part of the button.
It seems that I was moving the main view as the inner view height was changing. I guess if the UIButton is outside the bounds of the self.view then touches are not received.