I have a scrollview in my app, in the scrollview there is a lot of buttons without any space between them... When I run the app, I can't scroll because I "of course" have to touch a button first, and ehen I try to scroll, the button that I touched gets highlighted, and when I release.. The button is pressed! So I can't reach the buttons that is further down in the scrollview!
All button has the setting "Touch up inside"..
I guess it is kinda easy to fix, but I don't know how! :P
/Noob
Setting the property canCancelContentTouches on the UIScrollView to YES should allow it to cancel the touch event already sent to the button once it detects a scroll. That should fix your problem.
You can do what ksoderstrom said or you can auto scroll using this method for your scrolview
[self.scrollView scrollRectToVisible:textField.frame animated:YES];
textField can be a UIButton as well. This method will just move the scrollView to whatever component you specify.
Hoep it helps.
I had the same problem and i found out that it's really hard to test it in the simulator. When the code run on the actual device, the scroll view was working as it was supposed to...
Related
I have a subview with a UIButton added to a UIScrollView.
The button is working perfectly as long as the user isn't scrolling.
If the UIScrollView is still scrolling when the user clicks on the button, it just stops the scrolling instead(like if a row had been clicked).
Anyone know how to fix this?
First, make sure this really is the behavior you want - iOS users are used to scrolling views and touching to stop them with a tap without triggering button presses. Non-standard behavior (even when you think its better then the standard behavior) can be confusing to users used to how things work in other iOS apps - it can violate their mental model. Ok, note of caution over.
So how do you fix this? UIScrollView delays sending touch events until it knows if those touches are scroll events. You problem is a user tapping is a scroll event when the UIScrollView is moving. Two possible solutions:
Stop the UIScrollView from delaying any touch events it gets. You can set any scroll views delaysContentTouches to NO, which will stop the delaying action and should allow your buttons to be tapped while scrolling. You can read about it in the UIScrollView class documentation. You will also want to read up on canCancelContentTouches there as well.
Subclass the UIScrollView to add your own logic about where touch events should go. Here is a blog post that discusses how to do this.
First off, how do you test scrolling in the iPad simulator? I have a touch pad and I've tried dragging two fingers and I've tried click & dragging two fingers, but I can't get it to scroll. Am I doing that part correctly?
Assuming that I'm testing properly, why won't my scrollview scroll? I have a basic view controller in my storyboard and I dragged a scrollview into it. I made an outlet from it into my code and then in my code I generate a bunch of buttons and add them to this scrollview. They get displayed properly. Am I missing something?
set scrollview content size such
[MyScrollView setContentSize:CGSizeMake(320, 500)];
this is for iPhone for example.
You can also make two fingers by press the alt key next to cmd in mac
HOLD PRESS alt + mouse move on simulator
set contentsize of the scrollview,to enable scroll.
Detailed explanation
https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/UIScrollView_pg/CreatingBasicScrollViews/CreatingBasicScrollViews.html
You have to define the contentSize of scrollView which is generally bigger in frame than parentview or its frame to make it scrollable.
[viw setContentSize:CGRectMake(width,height)];
set it in viewDidLoad or where You alloc srollview.
Is it possible to present my modal view controller with the keyboard already visible? Currently, the modal's text view becomes the first responder as soon as it's view is loaded, which causes the keyboard to animate coming up from the bottom.
I'd like the keyboard to already be on the modal and be a part of it's transition. Any suggestions?
The keyboard is a separate UIWindow object. It is not in the same view hierarchy as your view controller's view. To make this happen, you would have to dig around in the UIApplication's windows property for the keyboard window and replace its default animation with a custom animation.
You could try putting the becomeFirstResponder code in vieWillAppear, but that isn't the "right" thing to do anyway.
You will probably need to replace the actual keyboard animation with a custom animation to force it to load immediately and without scrolling up.
I'm working with Xcode doing a Ipad app.
i simply want user to click anywhere on screen (not counting text fields) to perform some IBAction.I'm using an invisible button that covers my whole view.
Since I have some text fields in my view,i need to add this invisible button to the background of my user interface. I cant seem to find this option in the button attributes? any help?
Just set the button's type to custom.
Did you try setting the opacity of the button to zero?
I guess i got your point. You just want to put the UIButton(invisible) on the back of all the UITextField. The simple solution to this is open the Document Window in the IB. Now expand the view tree in the list view. Just drag your UIButton above the UITextFields and set the alpha value for the button in the property to be zero.
Hope this helps!!
iPad users don't "click". They "tap" or "touch".
In Interface Builder, I believe views are constructed with a z-index from top to bottom as they appear in the document window, so dragging your button so that it appears as the first subview of your main view should be a quick fix for this.
Have you considered other approaches? This doesn't sound like standard behaviour for an app and will probably cause havoc with anybody using Voice Over. What are you trying to accomplish?
I've a scrollview and on both sides, I've two buttons left and right.
when i click the scroll view will move left and when right button is clicked it will move right side. My scrollview has 20 buttons (approx) & on click of each button some action is performed.
Everything is perfectly implemented and working fine.
Only thing i couldn't implement is to prevent scrolling by touch. I don't want user to scroll the scrollview manually. How can i prevent it from scrolling by touch and still able to click the buttons inside the scrollview ?
Try setting yourScrollView.scrollEnabled = NO;. That should do exactly what you want.
Swift, set scrollView.isScrollEnabled = false and it should work!
Swift 3
self.scrollView.isScrollEnabled = false
If those buttons are the only interface for users, disable 'User Interaction Enabled' option of the scroll view in the Interface Builder. Or, programmatically, set userInteractionEnabled property to NO.
Maybe your issue is that when using UIView.animate and the options:
[.allowUserInteraction], is not set.
After this option set, the scrollview should stop on tap.