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.
Related
I have a ScrollView which behaves like a Slide Show. It automatically slides to the next image and in the end it goes back. But while this happens i don't want the user to slide in the scrollview him self. What i do want is to make each image that slides clickable so that the user can open a specific image for example for more details.
The default setting for the scrollview is userinteractionEnabled = FALSE. No user interaction allowed so the user cant scroll. But this also disables the click on image action. When i set it to true i can click on the image but i am also able to scroll again. So what's the best way for this?
I have considered adding a transparant UIView over the scrollview and make this clickable and check which item was shown in the scrollview. But is there another way for this?
userInteractionEnabled should be set to YES, however, you can set the scrollEnabled property to NO.
With scrolling disabled, you can still adjust the scroll position programmatically, but the user can not scroll. This should work just fine for you.
I created an app where users can touch buttons on a scroll view to go to another view, but when you scroll, it gets stuck on the buttons, and can only scroll when not touching the buttons.
So I suppose touch up inside would fix this but how would I make all my modal connections into touch up insides?
If you're using the storyboards, then they should be on touch up inside by default.
My guess is that your scrollview has Delays Content Touches disabled, you can set them via interface builder or self.scrollView.delaysContentTouches = YES;
I am trying to create the same type of slide-up/pull-up menu (from the bottom) as the Any.do iPhone app, but not having any success.
The issue I am running into is the app was built with storyboards so I am thinking I might have to scratch that idea and use just code.
Any ideas?
There is no need to get rid of your storyboard to recreate this, that's what IBOutlets are for. Any way, it looks like this was made by creating a UIScrollView that takes up the entire screen. Then add a UITableView to the upper section of the scroll view. Mind you in order for this to work, you'll need to disable scrolling on the scroll view in the background.
From there you can programmatically add the other elements to the scroll view to be rendered off screen, since there are only three they can probably just be buttons. And finally, since scrolling is disabled on the background scroll view you can add an image with a UISwipeGestureRecognizer at the bottom of the screen to manually change the scroll view's content offset property.
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...
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.