I am having a customize user interface for my iPad Application, and There is a dragging of an Object and button event simultaneously. My Problem is that when i drag the object the animation start working and when i leave the object the animation still working for few time. In the mean time while i am trying to press button or dragging another object, its not working till the animation completes.
If you want to interact with the UIButton that's animating:
Using (core) animation; you can't interact with the elements during their animation cycle (the regular way).
Only when the animation is finished you can interact with them again.
You can make your own touch handlers on the main view which checks if the touch is 'nearby' the animated button.
If you want to interact with the 'rest':
Make sure you animate your object using the UIViewAnimationOptionAllowUserInteraction parameter:
During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.
Related
I have five UIButtons in my application.All these UIButtons are stored in Array.As my Code Show below
NSMutableArray *Buttons = [NSMutableArray arrayWithObjects:btn1, btn2, btn3,btn4,btn5, nil];
Now i Want to move all these UIButtons in Specific Direction Continiously.As my image show below
I Already did some animation in CAkeyframeAnimation,but As a iOS beginer its difficult for me to perform these type of Continious Animation on multiple UIButtons using CAKeyframeAnimation.Can some one help me about this.Any help will be appriated.
I don't know what you've done already, but you could use UIView Animations and then make sure you enable set the UIViewAnimationOptionAllowUserInteraction option.
You can then put a gesture recognizer on the buttons.
To get it to animate, just use UIView's block based animations, there are only 4 that need to be done, and have them repeat. It's fiddly, but it's a quick and dirty solution.
If you are trying to move these buttons around in a way that keeps them reactive to user touches, using Core Animation directly is probably not your best bet. My answer below is based on this assumption.
When a Core Animation-based animation is running, the layer you see moving on screen (the "presentation layer" — see here for more info about this) does not register touches at its current position, but only at the final position of the animation, which is invisible for the user. Thus the moving bouton will behave most of the time as if it is disabled. Though it is possible to hack around this, it is not very convenient and not meant to be used that way.
Another drawback is that CAAnimation is not very flexible once created, for example it would be tedious to stop the movement of the buttons at their current position if you ever needed to.
Instead, you should compute and move your UIButtons frames manually. To synchronize the movement with the display refresh rate and have a smooth animation, use CADisplayLink, which is a very easy to use class that you can use to register a method that will be called back each time the display is being refreshed. In this method you should update your views frames based on the desired behavior of your views.
I have a couple places in my app where UI elements reset themselves when a touch ends on them. For example, hiding a dashed outline, sliding a view back to the default position.
The problem is that on occasion the app loses track of the touches. One example is if I slide the view upward and cause a UIAlertView to show, the view doesn't slide back, because the reset code is in touches ended. The touch ends during the time the UIAlertView is active, and the view doesn't reset. The same example works for hiding the dashed outlines.
My question is, where/how can I handle the reseting of these custom UI elements so that when a touch ends without being noticed it will still reset. TouchesEnded isn't always doing it for me.
Have you try touchesCancelled? I think it is called when the touch get interrupted.
EDIT: If this doesn't work then maybe you can manually add code that cancel the touch when you initiate the alert.
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 need to handle a touch event on my custom uiviewcotroller. I have a sub controller within the view that already handle touch event (it's a plot that handle zooming and scrolling).
I want to make a tabbar disappear when I tap the screen once. Actually it only works (even tought the tabbar doesn fade away but simply is no visible) in the areas in which the subcontrol is not present but I need it to work everywhere still handling the subcontrol events.
Make sure you're calling the superclass's event handler method in your event handler method to continue propagation of the event up the responder chain.
Also make sure the subcontrol's exclusiveTouch property is set to NO.
You might want to have a look at the event handling documentation.
Try to set userInteractionEnabled = NO in subcontrol view.
UPD: Try to add transparent button to subcontrol.
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.