How Can You Stop iOS PinchGesture from Selecting Buttons? - iphone

I'm currently writing an iOS application for the iPhone with one particular feature that creates a flowchart on the fly. The flowchart that is created is one enormous, scrollable view. Each information node of the flowchart contains buttons that automatically moves the view to the next information node. At any point in time, a user can use a pinch gesture to zoom out of the current information node and see the flowchart in its entirety.
My problem is this: I notice that if a user begins this pinch motion with one of their fingers tapping one of the buttons in an information node then this gesture takes precedence and the next node is shown as opposed the pinch gesture zooming out from the current node.
I've been looking on StackOverflow and have tried several things to fix this, but nothing yet has seemed to work. I was wondering if anyone has had similar issues and if they were able to overcome the issue?

Using #Till's advice and looking into my issue a bit more, I've done something that's worked for me and I thought I would share it here in case anyone else had similar issues or desires.
I was able to create UIViews that I could use to act as semi-buttons. For each of these views, I greated UITapGestureRecognizers and targeted them towards methods that would check to see if the sender's state is StateEnded:
-(void)handleButtonTap:(UITapGestureRecognizer *)sender
{
if(sender.state == UIGestureRecognizerStateEnded)
// Go on and do the code here
}
However, wanting to still maintain the look of the original iOS Buttons I did one step further. For each UIButton that I created, I did not associate a target with these buttons and instead created UIViews for each button. These UIViews were completely blank with a background color of "Clear." In this manner, I can now have my buttons, but still get the functionality I desired.
I hope this helps anyone else with similar issues. Thanks again to #Till for the advice.

Related

How to replicate the CNN iOS app pull down menu

Does anyone know how CNN is doing their top pull down menu?
It looks like a UITableView that is called with a touch drag event but wasn't sure. Googled various keywords but was not able to turn anything up. Just looking for some guidance on how to replicate this behavior.
I've no idea how it's actually done, but I know how I would do it: any view can sit completely or partially offscreen and be dragged onscreen by the user in the usual ways (e.g. a swipe or pan gesture recognizer). There's nothing special about that.
I guess they are doing something like https://github.com/mikefrederick/MFSideMenu
You have to customize "MFSideMenu" a lot though. If you dont want to show this menu on every view you need to disable UIGestureRecognizerDelegate on that view.
There is also something like https://www.cocoacontrols.com/controls/pullableview but you may need to add UIGestureRecognizer to this class.

Distinguishing between tapping a button and holding a button down on iPhone

In my app, I have a button that triggers an action. However, I'd like to do the following instead.
If the user taps the button, then trigger tapAction.
If the user holds the button down for, say 1 second (getting a sense of the right length of time here would be great, too), then trigger holdAction instead.
Many standard apps seem to have this capability, so I'm certain it's possible. If you could point me to the right place in the documentation, that would be great.
Thanks.
The answer to this question should cover it. The question talks about UITableViews but the method is the same for any UIView :)
You should take a look at UIGestureRecognizers to see what else is out there.

Creating a tableview in the form of a 'film strip'

I am developing an RSS-reader-type application. I am toying with the possibility of using a normal TableView application but showing the articles as a film-strip. I am mainly thinking for an iPad application (but possible it works on the smaller iPhone as well).
The idea is to have the cells passing/scrolling across the screen using swipe touches (but horizontal, and not vertical as with the normal TableView). They will be some-kind of miniatures of the full article, and when tapped (or with multi-touch zoom to have better control) can be enlarged to read. Then can then just be be moved on as soon as the user has seen enough of it.
Does anybody know if there is an easy way of accomplishing something like that?
The most obvious solution that springs to mind would be to use a UIScrollView, as this will provide the inertial effects, etc. for free - all you'd have to do it populate it with the relevant sub-views. (UITableView's actually use a UIScrollView.)
For more information and sample code, see Apple's UIScrollView docs.
If you want horizontal scrolling, take a look at Jeremy Tregunna’s JScrollingRow. It’s open source under a public domain licence.

Switching Between Subviews in iPhone App

So, in an iPhone app I am working on, I've decided that the best way to display all the contents to the user is to have the top part of the screen show some information, and the bottom of the screen show different information. However, the bottom part will change sometimes, so I was working on implementing that.
Another app that does this is the MTGLife app, here are some pictures:
http://picasaweb.google.com/lh/photo/HILMaJPnbLxP6hQRkn_6XA?feat=directlink
http://picasaweb.google.com/lh/photo/d5wpS8x_aRyAEOBpYYIxwQ?feat=directlink
http://picasaweb.google.com/lh/photo/RW-BQfqx-VytRim3BxeRZQ?feat=directlink
You see that upon hitting a button, the picker switches over and displays the log. Hitting the same button switches them back, with a pretty animation. I would like to do the same thing in my application. I'm not sure the best way to go about it though...
I was thinking that I would make 2 UIViews, and then would simply flip between them, but I want to get some opinions first on how to do this, and then a push in the right direction.
Thank you!
The 2 UIViews is a good approach. By using the UIView animations functions, you can switch between the Log and the Picker with the desired transition.
In the UICatalog sample application (see TransitionViewController), there an example on how to animation two subviews

Iphone default behaviors that need to be implemented?

When I've learned that I have to write some code to make the iphone keyboard go away. I was quite surprised. I was surprised even more when it become apperent that it is just the top of the iceberg.
What are the expected UI behaviors that aren't provided by system OOTB?
Is the list below complete?
The expected UI behaviors:
Focusing next text field when [done] is hit
Hiding the keyboard when background is hit
Using Touch Up Inside to fire a button action. (To give user opportunity to change his/her mind)
Supporting the screen rotation.
Some of that is silly, but some of it has uses as well.
Focusing next text field when [done] is hit
Which field is "next"? If you have a large form with fields both next to and above/below each other, next might not be so obvious. Even if they are in some linear layout, the iPhone would have to work to figure out which one is next. Do you want to wrap around at the end of the form, or dismiss the keyboard, or submit the form?
Hiding the keyboard when background is hit
I mostly agree with you here, though there are a few cases where this is useless. For example, adding a new phone number in the contact app.
Using Touch Up Inside to fire a button action
This one I really don't get. I can only guess that it's designed to allow you to use buttons instead of the touchesBegan/Moved/Ended methods. I guess it could be useful, but I've never used anything but Touch Up Inside.
Supporting the screen rotation
Many apps just don't work in any other orientation, such as games. If you want to use rotation, you only have to add two lines of code assuming you've done your layout well.
I hope this helps explain some of the strangeness. Aside from the keyboard dismissal, I've never really found anything too annoying. The one thing I wish they supported was using the highlight state of UIButtons for the set state. It would be a quick and easy toggle button, but I've taken to screenshotting a highlighted button and using that for the background image of a selected button.
Want a rounded rectangular button that isn't white? Since that one uses a background image, you can't just click something somewhere that makes it the color of your choice. You have to create your own image or you could even use CSS (WTF!?) to do it.
Unfortunately, the iPhone SDK lacks a lot of helpful things one would think would just be there. However, many people have taken the time to write wrappers for many of these kinds of things to help facilitate development - a quick google search into the functionality you are expecting may turn up a lot of useful answers!
For example, you could make the keyboard go away when you tap outside of it by creating a new view when it appears, and placing that view behind any user-interactable views on the screen. When that new view is tapped, it will become first responder and cause the keyboard to slide away (because the UITextField is no longer first responder).
Such a thing could be easily implemented as a drop-in fix for pretty much anything you'd need it for with very little code.
Still should have been included in the SDK in the first place, though!