UISlider thumb stops dragging - iphone

I have a UISlider in a view, in a typical detail View Controller. When I touch the slider's thumb, I can drag it to the left fine, and once I've dragged it left, I can continue to drag it wherever I want, but when I drag it right, it moves a few pixels and then the drag stops.
I read at UISlider only slide a small distance that it may be related to gesture recognizers, but I don't have any recognizers active in this view. I've tried temporarily removing any recognizer that might interfere, but that didn't help.
I don't have any sample code to include because there's really not much code involved in the case I'm having trouble with. I have a UIViewController subclass that has a UISlider on it, and I have an IB-generated action for the "Value Changed" event. This fires, and as I said, I can drag the slider left, but not right.
I tried changing the action so all it does is NSLog the slider's value, and that doesn't help.
I expect the problem is some interaction withs something else in the app I'm working on, but I'm not sure where to look. I'm looking for some ideas as to what could be causing this.
Update
So I found the problem. It's a bug in iOS 5.1, described in iOS 5.1 swipe gesture hijacked by UISplitViewController - how to avoid?.
I tracked it down by enumerating all the gesture recognizers (by walking the view hierarchy from self.view.window and dumping them) and then selectively removing them, then Googling on the one that ended up causing the problem. Pain in the butt. Leaving this here for the next victim.

I posted the answer as an update to the question, but in a nutshell, it's an iOS 5.1 bug. The pan gesture recognizer for the split view controller is interfering with the slider. My workaround is to disable that recognizer.

You are probably trying to increase the value of the slider to something greater than 1. You need to enter a float between 0 and 1, such as 0.46.
Look through the part of the code where you update the value and check that.

Short answer:
Try setting slider's propery continuous to NO.
Long answer:
I encountered a similar problem: slider's thumb would not move on iPad 5.1 Simulator. No problems on iOS 6 though.
In my case, I was setting slider's minimumValue and maximumValue to some other values in code. The problem disappeared after I set continuous property to NO. The relevant fragment of code:
self.precisionSlider.minimumValue = 0;
self.precisionSlider.maximumValue = 15;
self.precisionSlider.continuous = NO;

Related

Swift: How Do I Stop A Pan Gesture from Cancelling When a Timer Fires?

This question is brief and I don't believe it requires showing code, but I'd like to learn why my app is doing this.
In my ViewController, I have a countdown Timer that fires every second and updates a label in the view with seconds -= 1 (for example). Everything's working perfectly as it should... no big deal.
But, I also have a UIButton in this same view that I can drag around. The problem occurs every time my Timer() fires (every second)... My PanGesture (dragging the UIButton) is cancelled and the UIButton is dropped.
Is there a certain property that I need to set on either the UIButton or the Timer to prevent this from happening?
Many thanks for your advice!
Even though I haven't been able to discover the reasoning behind it, here's what's I've learned:
If you are in the middle of a UIPanGesture (dragging a UIView around) and you try to update the text on a label (ie. update the UI), your UIPanGesture will cancel and .ended will be called. This was happening for me every second when my timer was updating the text on the label.
In my application, the label showing the countdown value is originally hidden (alpha = 0) in my view even when I am performing the text updates on it, and my UIButton to drag around is only visible when my countdown label isn't.
So my workaround was to only update the text on the label when it's actually visible. That way, my UIPanGesture isn't affected while I can drag it around, but when the label becomes visible and my UIButton isn't, then I can update the text on the label as desired without worrying about dragging the UIButton around.
I know it's a very custom fix that works for me, but if anyone knows what causes the issue, please do share :)

UIScrollView - how to get rid of delay before scrolling?

I'm using a UIScrollView to display a custom UIView. When the user drags a finger across the UIScrollView, there is a noticeable delay before the display begins updating. If the user keeps touching the screen, the UIScrollView becomes very responsive after a short time. Subsequent attempts to scroll result in the same initial delay, followed by high responsiveness. This delay seriously affects the usability of the view and I would like to get rid of it.
In a test project I have written to try to get to the bottom of this issue, I have only been able to partially replicate the behaviour. The first time that the user scrolls is exactly the same - however any subsequent attempts to scroll are responsive straight away.
I have tried both setting delaysContentTouches = NO and subclassing UIScrollView so that touchesShouldBegin returns NO as suggested in multiple places online, but neither has worked.
I'm using MonoTouch on iOS 4.3, but Objective-C answers are fine. I would post code to help illustrate the issue, but since I have been unable to narrow down the problem this would be well over 1000 lines. Hopefully this is enough info to get a solution.
Does anyone know what might be causing this delay, and how I can get rid of it?
Some general suggestions for improving scrolling performance.
Have your scrolling views rasterize offscreen:
myView.layer.shouldRasterize = YES;
Set that property for each sub-view on the scrollview - do not set it for the children of those sub-views or you just eat up memory that way.
If your scrolling views do not need compositing, make sure you turn that blending off:
myView.opaque = YES;
Test using the simulator by leveraging these two features that appear on the Debug menu of the iOS Simulator:
Color Off-screen Rendered
Color Blended Layers
If that doesn't address your problem, and you have implemented UIScrollViewDelegate, double-check to make sure you are not doing anything time consuming in those methods - for example, based on your description, you might be doing something in scrollViewDidScroll, scrollViewWillBeginDragging, or scrollViewWillBeginZooming and if you are, optimize that so it happens before scrolling even begins. Also, make sure you're not doing anything in touchesBegan.
I suspect what is happening is there is some kind of interaction enabled in the content of your scroll view.
The system does not know if the initial touch down is going to be a tap on one of the subviews or a drag on the scroll view, therefore is causing a delay while it waits to see if you are going to lift your finger.
What are the subviews of the UIScroll view?
As an experiment set all the subviews of the UIScrollView to have userInteractionEnabled = NO, this will not be what you want, but its just a test. Is should scroll fine after this, otherwise I am wrong.

Swipe to change UIViewContent

Hej folks,
I got an UIView in my application and want to implement kind of a swipe gesture. I know how I detect this gesture (touchesBegan: and touchesEnded: for example is x coordinates are distanced more than 100 pixels or something else) but I really donĀ“t now how to animate my needs. In fact my UIView will contain subviews which are 9 UIButtons. On swipe I want to change the set of buttons programatically...any solutions out there? Primarily need the animation!
EDIT: I thought about programatically moving the buttons off-screen to the left and at the same time move the new ones on-screen from the right side. But it seems I don't really know how to realize this...isn't it too much leaking at the same time? Please give me a hint!
It's seem that you want to recreate somethings like the springboard but with button instead of icon.
I can suggest you to use UIScrollView.
why you don't load just a new view with the other button set in your window after the swipe gesture was detected?

UIScrollView with embedded UIWebView not scrolling after holding

I have a UIWebView which is embedded in a UIScrollView. The webView is resized so that the scroll view manages all the scrolling (I need control over the scrolling).
In the webView I have disabled userSelection via '-webkit-user-select: none;'
Everything is working fine except one annoying detail. When I hold down my finger on the content before starting to scroll for about a second the scrollView won't scroll. My best guess is, that it has something to do with userSelection. The time is about the same it usually takes for the copy/paste/magnifying-thing to appear which usually disables scrolling as well.
I am running out of ideas on how to solve this. Every help would be greatly appreciated!
Thanks!
EDIT: Another aspect of the problem is, that the non-scrolling actually triggers JS-Eventhandler (click, mousedown, mouseup) inside my webView which leads to surprising app behavior. The user puts her finger down, waits, scrolls, nothing happens, removes her finger and this is perceived as a click, which feels wrong from a users perspective.
I would guess what is happening is that after that short duration, the scrollview is no longer interpreting the touch as being on it's view and instead passes the touch down to it's content views.
Have you tried delaying the content touches for the scrollview? This will essentially tell the scrollview to delay taking action on the touch event and instead to briefly monitor the touch and if the touch moves then it recognizes it as a swipe gesture for scrolling. If it doesn't move, it will eventually pass the touch along to it's subviews.
scrollView.delaysContentTouches = YES;
I think even then, there is a standard delay time before the scrollview will pass the touch events along the responder chain. If you hold for too long, it's going to naturally perceive it as being a press down event rather than a scroll event.
This question is not relevant anymore. As of iOS 5.0 the UIWebView is based on a real UIScrollView and also exposes that UIScrollView via a property. Use that instead.
And don't mess with UIWebViews embedded in UIScrollViews anymore. The documentation explicitly advises against that.
Relevant Documentation

Making view transitions fast - do you use this hack?

I have an iPhone app that displays a modal view controller. The modal view controller shows two instances of a custom subclass of UITextView called RoundedTextView, an MKMapView, and a UIToolbar. I construct the viewController only once, and reset its data and present it each time the user summons it.
When showing this view controller with presentModalViewController, I noticed that the animation to show the view was choppy on the 3G. So, to speed it up, I set the alpha of the MKMapView and the two RoundedTextView objects to 0 on viewWillDisappear and back to 1 on viewDidAppear. This made it nice and fast. I also presume that I could remove the views from the superview to speed it up as well.
Does anyone else jump through these kind of hoops on the iPhone. Is there something else I should be doing to avoid this hack?
It's not a hack to simplify drawing during animation in order to make the animation more smooth. It is indeed a very valid technique.
You may be able to achieve similar performance improvements by setting all UI elements to Opaque, a technique also used to fix table view cell performance issues. You just have to make sure background colors match.
The main problem I had was I subclassed UIButton to make gradient buttons and I had the boundary mask enabled. This made the performance terrible. I removed that option and made my buttons square and it's blazin now.