I am creating a semi-piano app in Objective-C for iPhone; it's in fact a diffrent layout MIDI Controller, but I'm still working on the design.
I created all of the "keys" with UIButtons, and I want to be able to slide to them or from them to other UIButtons.
I read all the similar questions before, but I couldn't make it to work with touchesMoved,
Because it only worked from the view if I didn't drag the finger from a UIButton.
Thanks in advance, code will be appreciated!
Are your buttons created in IB? The default event when connecting buttons in IB is "touch up inside", which means the action is fired when the user ends a touch (lifts the finger) inside the button. A piano key or similar would be more appropriate to fire on the "touch down inside" (for the initial press) and the "touch drag enter" (for when a finger that is already on the screen moves into the button).
Since you are doing it programmatically, you can add targets to the buttons as described here:
http://developer.apple.com/library/ios/documentation/uikit/reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instm/UIControl/addTarget:action:forControlEvents:
Just include the events you want in the mask.
Related
I am working on a musical instrument type app. It uses a keyboard like set of UIButtons to trigger playing a musical note when touchDown occurs. The note stops playing based on touchUpInside or touchUpOutside events.
Everything works as expected except when attempting to play multiple notes. The touchDown events work, but touchUpInside event is not sent when a button is released as expected when another button continues to be touched. The touchUpInside is sent to all the buttons when all the buttons are released.
It appears to buffer other touch events until the button being held is released. If a button is released and another pressed, the touchDown and touchUpInside events are not sent to that button until all the other buttons are released. Then the touchUpInside events are sent to the first buttons and the subsequent events are triggered.
This flow has been traced through the code for the IBActions for the events. I have enabled multitouch. I have tried allowing multiple gesture recognizers. Nothing seems to affect this behavior.
There is no real code to share as the buttons and events were built using Interface Builder - Storyboard.
Is there something holding up the processing of events pending the release of previous touch events?
Any suggestions would be appreciated? I have searched for other similar questions but could not find this issue.
Thank you!
As your piano keys, use custom views, not UIButtons. You can probably most easily track the kind of touches you want to detect by attaching a UILongPressGestureRecognizer to each view. Or, at a lower level, you could simply detect touch events directly.
I am trying to add a touch to UIButton.
I want it to be when I click on button, until I release the finger, it won't click on it.
I Have played with many touch events, Touch down, Touch up inside etc but none is working like that. This is a very common touch event. How can I add such a thing in iPhone UIButton?
Touch up inside will only execute when you remove your finger from the button
Touch down event will work as soon as you touch the button.
Sample Project:
https://www.dropbox.com/s/hm82u553ktyszbd/ST-16385963.zip
Touch up inside is the event you should use here. If it doesn't work, that means you haven't implemented it correctly.
Could you post your code? It sounds like you want the Touch Up Inside functionality of not firing until the finger is raised.
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.
I created my own custom view that extends UIControl. This custom view has its own touch implementation. I implemented touchesBegan, Moved, Ended, and Canceled methods in it.
In the main view controller, I created several instances of this view. So in the screen, there are a number of custom buttons.
I want to disable multitouch in my app. If I click one custom button, then other buttons shouldn't respond.
Actually, it was easy to implement this. While I held some buttons, I could just make other buttons' userInteractionEnabled property to NO until I ended touch.
But the problem is that when I tap these several buttons at the same time, two or more touchesBegan methods work simultaneously, and message passing is messed up.
I tried to set multiTouchEnabled = NO and exclusiveTouch = YES, but it still didn't work.
How can I force to disable multitouch in my app?
Thank you.
You need to set exclusiveTouch to YES, not NO (which is the default anyways). The name of the property refers to the view being the exclusive recipient of any touch events for the duration.
I'm about to start a new iPhone app that requires a certain functionality but I'm not sure if it's doable. I'm willing to research but first I just wanted to know if I should at least consider it or not.
I haven't seen this in an app before (which is my main concern, even though I haven't seen too many apps since I don't own an iPhone), but an example would be the iPhone shortcuts panels: you can hold on an app, and then drag it to another panel, sweeping while still dragging it. But this is the core app, is it possible to reproduce something similar within a normal app?
I only need to be sure it can be done before I start digging, I don't need code examples or anything, but if you have some exact resources that you consider helpful, that would be appreciated.
Thanks!
Yes. If you have your custom UIView subclass instance inside a UIScrollView, your view controller just needs to set the UIScrollView to delay content touches and not allow it to cancel touch events.
[scrollView setCanCancelContentTouches:NO];
[scrollView setDelaysContentTouches:YES];
When the user taps and holds in the custom view, the event goes to that custom view, which can process the touch events to drag an item around, but if the user quickly swipes, it scrolls the view.
The "panel" view that you're referring to appears to be a UIPageControl view — although, perhaps, the specific incarnation of this view that Apple uses for the iPhone's home page may be customized.
Instances of generic UIView views that you might touch-and-drag will receive touch events. By overriding methods in the view, these events can be processed and passed to the page control, in order to tell it to "sweep" between pages.
If I wanted to do what you're asking about, that's how I might approach it. It seems doable to me, in any case.
Start with this: Swip from one view to the next view
Try using a UIButton that tracks the time since the state of the button changed to "highlighted". You may need to do this in order to track the dragging and move the button around:
Observing pinch multi-touch gestures in a UITableView
Check to see if the button starts overlapping one side of the screen while being dragged. If s certain amount of time elapses since the button first started overlapping the edge and then manipulate the UIScrollView so that it switches to the next page on the corresponding side of the screen
You may need to use NSTimer to keep track of how long the button is held down, etc.
In any case there's no reason why this couldn't work.
If UIButton doesn't work then perhaps try a custom subclass of UIControl (which tracks the same touch down actions etc.). If that doesn't work then use the window event intercept thing to track everything.