iPhone SDK allow touches to affect multiple views - iphone

I have a main view that has has two buttons on it that control methods to display the next image and display the previous image. In this case the 'Image' is a class that inherits from UIImageView and has multiple pictures on it that you can interact with, and I call this class a 'Pane'. The pane itself handles all the user interaction itself while the main view controls the display of next and previous panes with the buttons. Here is my dilemma, because the pane fully covers the main view it wont allow for the user to tap the buttons on the main view! So once a pane pops up you cannot change it via the buttons! Is there a way to allow touches through transparent parts of a view, or if not how in the world do I achieve this?!
I cannot pass touchesBegan or any of those methods from the pane to the superview because all of the button touch methods are created in the xib file.
I cannot insert the pane under the control panel because then you wouldn't be able to interact with the pane. And as far as I know theres no way to pass touch events to every single pane within the paneHoldingArray that belongs to the main view
I cannot add the command buttons inside of the pane because I want to be able to replace the command button's image with a thumbprint render of the next/previous pane.
I've been stuck on this for a very long time, please somebody help me out with a fix action or a new way to re-engineer the code so that it will work!

If you want the buttons to capture events, then layer them above the pane. You say you cannot put the control panel above the pane, so break the buttons out into another view that you can put above the pane. If you want the buttons to appear under other views, then make some completely transparent custom buttons to handle you actions that you can layer on top.
I don't know what you mean by the button touch methods are created in the xib file, but in general you cannot effectively pass touch events around. You must organize the view hierarchy so that the views you want to receive events are logically on top. However, nothing says that the views on top have to be opaque or even visible.

Related

Can I put my buttons into a separate view?

I am saving a picture of my base UIView via UIImageWriteToSavedPhotosAlbum.
I have not created a separate UIImageview, everything is in the same base view, including my buttons, therefore when I save the picture, it includes my buttons too.
Is there any way I can put the buttons in a separate view, so that they are still visible in the app, but do not appear in the picture that I save via UIImageWriteToSavedPhotosAlbum?
Have you tried hiding the buttons with .isHidden just before you call UIImageWriteToSavedPhotosAlbum? Then re-enable them afterwards.
Alternatively you'd have to put the buttons on a separate view that's not part of the one you're saving.

Hide keyboard plus return key?

I have a view with a textfield at the top, a textview under it and two buttons below the textview.
The keyboard is configured with a "Done" button. Once the user has typed in their info, they click the save button, which is below the textview. First they click Done to hide the keyboard (and reveal the save button) then click the save button.
I need to allow carriage returns in the textview but "Return" is already taken up by Done.
How is it usually handled when you need a Return key and ability to also hide the keyboard?
Drag a button into your view, delete the text, and resize it to take up the entire view. In the document outline, select the new button and drag it to the top of the list of elements. This puts it in the background so it is not hiding the elements of your view.
Add this code to your ViewController:
#IBAction func hideKeyboard(sender: AnyObject) {
self.textField.resignFirstResponder()
}
Link the button to this action and you're all set.
If you're using a UINavigationBar or have other buttons or fields, activating any of those UIControls could be detected and used to dismiss the keyboard via resignFirstResponder(). In fact Save/Cancel/Done are UIBarButtonItems and are a standard mechanism for completing things and changing state, and create a framework for accomplishing what you want. If you don't take that approach then you have to get creative with how you do it, and also make it clear to the user what needs to be done.
In Interface Builder you can change the type of your main view from UIView to UIControl and then use addTarget() to detect touch events as a 'touch outside' area and use those actions to resign first responder as well. But you might want to consider a UINavigationBar or some other button bar or tab interface to make state transitions.
Also review iOS Human Interface Guidelines document. It's a great document for understanding how iOS is designed to handle common situations like what you are dealing with, and it can get you out of design ruts. It's well written and worth re-visiting periodically.

Using UIPage Control

I have been trying to build a app where you touch three different buttons and then go to there new view. Its it possible to use a UIPage Control? If so How would you go about doing that. For example I have three views. Apple, Orange, Cherry. I would like the user to flick between these three views. I need them to be three separate views i can't just have the image change.
How would I go about using the UIPage Control and switching views?
UIPageControl doesn't deal with switching views itself, it just provides the dots that are typically displayed at the bottom of a paged view and it can be tapped to go one page forward or backward (instead of swiping the actual view). The actual view that displays the content is typically a UIScrollView with pagingEnabled set to YES.
When the control is tapped, it sends the UIControlEventValueChanged event to its target. You'll then have to scroll the UIScrollView to the right page yourself.

How to create a toolbar in a TableView with a Label?

I would like to add a toolbar with a label entitled "Save your search?" on the left and a button "Save" on the right that triggers a specific action when tapped. How could I do that programmatically, especially I want this Toolbar to show up only when a particular View is loaded on a screen but not on every view.
Also, I want the toolbar to have a static image as background. "Save" button will also have a static image for background
Just to check; why do you need to add this toolbar of sorts onto a TableView? Depending on how you've set things up; and specially seeing that you need to conditionally hide/show this toolbar, might be easier to add it outside the tableView (just above it I guess).
Seeing as you need to hide/show this toolbar at will; guess you can simply use a UIView for it and add the UIButtons on top as subviews; --> declare it as a property in the .h file so that it can be freely accessed in the .m file whenever you need to hide / show it.
Did you need help on some specific issue related to this perhaps; or would this serve as a goo enough starting point?

icon selector using two view

Need help with the following. I am creating two different combinations of view/controllers that allow me to add/edit a set of information , think tasks or some type of to-do. I have all the data capture/store functionality working.
I decided that it would be nice to have an icon associated to these tasks. So the icon would show up in the UITableview. I commissioned 18 customer 44x44 icons that would be added tot he table.
But there is where I'm stuck:
I was to add/edit views to have the capability to select an icon to attach to the tasks. In order to do so, i added a 44x44 round-rect button with one of the images as a default. I wanted to have that button trigger another view with the 18 icons so the user selects one and it passes control back to the main view and updates de selected icon appropriately.
I created this little 18 icon view together with the main view, which is based on a scroll view. I configured the little icon view to be hidden.
But I have no idea if the little view should be a subview of the main view, who should be the file owner, how do I make it appear hidden as the main view is displayed and toggle t as needed...
I am stumped. Anyone done something like this? Ideas? Things I completely messing up, you can think of?
Thanks in advance
Probably the easiest way to hide and show the view is to adjust the "alpha" property on the view. If you set the alpha of the little view to 0 it will be hidden, and when you set it to 1 it will be showing. So in your awakeFromNib function (or wherever you are doing initialization) you can add the littleView and set the alpha to 0 so it starts hidden. I suggest adding the littleview to your mainview unless for some reason the little view will have any part of it outside of the mainview. Then, when the user selects the icon to change it, you can set the alpha to 1. Finally, when the user chooses from the view, you would set the alpha back to 0.
Note:
This is not the most efficient use of memory because the view is technically always around. So if you think that you will be low on memory I would suggest creating the view programmatically when needed and removing it from mainview when the user is done. (But only do this if you think it will be an uncommon task because creating the view with a bunch of images will probably be a relatively expensive operation).