I have a quick question. I am trying to implement an application where the user can navigate between the screens via swipe gestures. So I am using gesture recognisers to push and pop views, the problem with that is that I don't want the transition animation to apply to the entire screen as there are certain similar components and it looks weird.
I considered using a scroll view, however I don't want to load all the controllers at the same time.
Any suggestions?
I'd suggest looking into UIGestureRecognizer and setting the UIScrollView property delaysContentTouches to NO to prevent the scroll view from consuming touch events before your gesture recognizer has the change to process the input, if you'd prefer that approach.
Don't forget that UIGestureRecognizer offers you quite a lot of information when the gesture fires.
I would suggest using a scroll view and load only the visible controller. You can then look for this delegate method, and load the other controller lazily
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Related
I would like to place custom views (created from nib) inside UITableViewCells. That works without issues, unless the custom view declares it's own single touch UIPanrecognizer. In those cases my custom view responds to the pan events, but that pretty much disables the ability to scroll the cells inside the table view. I tried registering the UIPanRecognizer with both the cell and the custom view, but that ability seems to be not allowed any more since IOS 9 (seems like this is also not how Apple wants touch events to be handled, I read somewhere that touch events should just be handled by one view)
I also failed to find a way to scroll the table view programmatically, which would also seem a little hacky.
What are my options when it comes to wanting to preserve the pan behaviour of the UITableView while still being able to respond to a pan event inside my custom view?
My use case is as follows: I want to reuse a custom view that can sideways-scroll that I created for another part of my app. My table view is set to only react to downward pans. Therefore the two pan actions are not interfering.
Two ways I have this solved currently are as follows:
The sideways scroll reacts to two-finger pans. This is super awkward and unintuitive.
All gestures on the custom view (except taps) get sent to its superview. A tap on the custom view disables the rerouting, which locks the table view and enables sideways scrolling by letting the custom view react to the sideways pan. Another tap restores the initial behavior. This is awkward since it asks the user to perform three separate actions for what should be just one.
I know that I can enable sideways panning for table views, but that doesn't solve my problem of wanting to reuse my custom view inside the cell.
Does anyone know a solution to this dilemma?
The solution was to create a custom UIGestureRecognizer.
I followed this tutorial, created a custom SidewaysPanGestureRecognizer, registered that instead and passed all gestures but SidewaysPanGestureRecognizer to the superview by implementing the UIGestureRecognizerDelegate method responsible for deciding if the view should handle the gesture:
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer,
shouldReceiveTouch touch: UITouch) -> Bool {
return gestureRecognizer is SidewaysPanGestureRecognizer
}
So I am working on this project here, to test some things that I am interested about, such as view transitions using UIGestures.
I am currently testing how view transitions behave when they have things like UIWebViews and UIScrollViews in them. What I have found out currently is that if you have a UIScrollView bigger than the view frame then the transition (using gestures) is blocked if you are using a UIGesture to change the view. (Such as swipe left or right)
I was wondering if there is a way around this or a solution that I don't know about..
Try using
gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
return no for it and see if that works.
I am a newbee in iOS development; and i want to develop a simple application.
In my application there is a view that is a member of xib. I want to receive user's touch and slide actions on my view to run some sliding animations.
I found some codes about this animation but i couldn't find how can i receive sliding action in UIView.
At least, i wanna explain why i used view. This view will contains two or more labes. So i couldn't be sure to choose Rect Button or UIView.
I hope you can help me.
You need to look at Gesture Recognizers. There are tonnes of resources and examples online. For example, here's an example on how to use swipe (slide) gesture recognizers.
I have 4 UIViews inside of a main view controller view. All I need to be able to do is drag the views around the "screen". Is UIScrollView the best option for this, or is there a simpler way?
Apple's Touches sample application contains code that does just this, so you might want to check it out.
UIScrollView should be used for scrolling, not dragging. And the 4 scroll views won't work if they're overlapped so don't even think of using UIScrollView in your case.
A dedicate UIView subclass that overrides -touches*****:withEvent: is needed. See http://github.com/erica/iphone-3.0-cookbook-/tree/master/C08-Gestures/01-Direct%20Manipulation/ for example.
I have a series of UIViews inside a UIScrollView, and the UIViewControllers for those views are not receiving the touch events. If I take the views out of the scroll view then it works.
I have enabled userInteraction on the views but it's still not working!
This must be possible and I'd be really grateful if someone could point me in the right direction!
Thanks,
Mike
Do the views have their own touch handlers, or are you relying on the viewcontroller to get the touches? Depending on how you have set things up, the views may be handling the touches without passing through to the view controller.
I have overcome this issue by overriding the loadView method of the view controller, and setting the view's instance variable to a simple UIView subclass which passes on the touches.
Check what you are returning in scrollview delegate method view for scrollin in scroll view.
As mahboudz mentioned - check if you have any custom handler for touch event. If not, please have one. Its far more relief to do whatever you want to do with your view. Check out Apples sample app from scrollViewSuite. They have tapDetectingImageView delegate. I used the same in my app it worked great! Hope this helps!
You may find this post useful. It's an example of a pretty clean way of intercepting events.
Have touch handlers for view for which you want to receive touch events and that will work.