I have a collection view cell which contains an UIScrollview in which all of the content sits. I want to have a gesture that allows users to swipe down when the cell is at 0,0 and then that fades away into the list view of the collection view.
However, I still want the users to be able to scroll down into the rest of the cell content.
Should this be contained in the same gesture? If so, how do I override a scrollview's gesture?
Thanks.
Yea just try implement this method from UIScrollViewDelegate:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
Get scrollView and calculate gestures and make behaviour. And look other methods for make best visual effect :)
Related
I'm using a paper fold animation To show some content from the top of the screen, over the tableView.
Right now i have a button that triggers this folding action.
I would like instead to trigger this action by swiping from top to bottom. but my TableView is full screen, so i figured if there is a way to make on UITableViewCell, or a part of the table, not scrollable, for it to trigger the Fold swipe instead.
I tried using the UISwipeGestureRecognizer But it doesn't work so well...
There are several ways to stop UITableView from scrolling. UITableView is a subclass of UIScroll view so you can use the UIScroll view methods to stop the table view being scrollable. So in your tableViewController you can call [[self tableView] setScrollEnabled:NO]. You should also be able to stop any user interaction on the table view by calling [[self tableView] setUserInteractionEnabled:NO] (a method on UIView).
You could subclass the UITableView and override the setContentOffset: method (another scrollView method), and only call [super setContentOffset:] when you actually want the table view to scroll (it's possible that you may need to override other methods as well.
You can also get hold of the pan gesture recogniser that the scrollView is using, this allows you to see exactly what messages the scrollView is getting for scrolling and you may be able to adjust the scroll offset accordingly [[self tableView] panGestureRecognizer]. Once you have the panGestureRecognizer you should be able to set it to wait for your swipeGestureRecognizer to fail using [UIPanGestureRecognizer requireGestureRecognizerToFail:. Which will mean that the pan gesture recogniser the scroll view uses will only start working if the swipe fails, you may need to make it so the swipeGestureRecognizer fails if it doesn't start near the edge of the screen.
I have a background image that is added to UIScrollView with zoom enabled. I am trying to add additional UIImage's on top of the background image that zoom together with the background image?
The idea is to have a background with multiple playing cards were the user can either see the whole playing field with small playing cards or zoom in the whole background including the playing cards for better views on the playing cards.
Your UIScrollview should contain a single zoomable UIView subview. That subview should contain your background UIImageView and all of the card UIImageViews as it's own subviews (if you add the background image first, it will be layered at the back of the resulting composite view)
The containing UIView that is the immediate subview of your scrollview should be the return value to the UIScrollviewDelegate method
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
You can manage your view hierarchy through a UIView's subviews property, which is an NSArray of views. They are layered in the order of the array, so the first view on the array will be at the back when the views are composited for display.
Well you could use the scrollviewdidzoom delegate method to notify you when the scroll view has been zoomed in and out.
From there you could do a number of things like present new UIImages at a specific zoom level using the scrollView.zoomScale property.
Let me know if this helps.
I've been driving myself mad over this one. It might be one of those things where I need to take a step back and figure out the simplest way to implement this. Can't find anything on this either. I google-fu'd the heck out of this one.
In the Pocket App when you pull down a menu reveals itself just like the searchBar does. In this instance the faux bar when you pull it past its halfway point if you release it shows springs into place. If it is release before the halfway point the bar will snap back and hide. As shown here
In my case I've been trying to replicate this with no luck. In my case I have a UITextView inside of a UIViewController view. I think I have it all wrong.
I can get it to work with a UIScrollView hidden by initiating with it offscreen and then when I press a button the UIScrollView reveals itself. The problem is that this method covers everything so I'll have to resize and relayout a bunch of views. Is this in a UITableView possibly? I want it to be a pull action though and just want to put some TextStrings/Labels in this bar.
Thank you in advance.
Feels like you need a UIScrollView (or UITableView) and to put the menu you want to reveal at the top (in the table view header, for example) and then get the delegate callbacks for scrolling.
UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
You might also need to watch for some of the dragging delegate callbacks
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
You can initially hide the menu by setting the content offset to the height of the menu, then catch the delegate callbacks for scrolling and, if the scrolling has reached beyond half the size of the menu set the content offset with animation.
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
If I understand your goal correctly you don't need the scroll view.
What I would do is have an simple UIView containing all the stuff you need and place it outside of the visible area. This will be your pull-down view. Then add an UIPanGestureRecognizer to the view in your UIViewController and use it to track the movement of your finger and update the frame of the pull-down view accordingly. Then in this update method you simply check if the position has passed some threshold and if so you let the pull-down view snap to its final position (using animations of course).
If you are unfamiliar with the UIPanGestureRecognizer there is a really good tutorial here:
http://www.raywenderlich.com/6567/uigesturerecognizer-tutorial-in-ios-5-pinches-pans-and-more
Imagine, there is a UIViewController with a UIScrollView in it. At the top of the view there is an UIImageView, some UILabels and other things. Furthermore, there is a UITableView which content is Dynamic Prototypes. I attach a picture to make it clear:
I haven't got a static amount of cells in the UITableView so it could be scrollable. My problem is the following: the UITableView scrolls in itself but I want to scroll the whole View. What is the best possibility to do that?
Possible solutions I've founded today
1) The first thing is: I create a UITableViewController and declare a header section in which I include all my labels, images etc. programmatically (I would love to use the interface builder for that...)
2) Another solution is to calculate the height of the view. I tried the best to do it like this way - but: without success. If this is the best way to do that: Can anybody give an example?
I would ditch the UIScrollView and just use a UITableView. You can add a UIView object as the tableHeaderView of the UITableView just by dragging it in in Interface Builder. Now since everything is part of the UITableView hierarchy, everything will scroll together as expected.
You could also try setting delaysContentTouches to NO on your scrollView. Depending on your setup, this may make the scroll view respond to the touch first instead of the table view.
From Apples UIScrollView Docs:
delaysContentTouches
A Boolean value that determines whether the scroll view delays the
handling of touch-down gestures.
#property(nonatomic) BOOL delaysContentTouches
Discussion
If the value of this property is YES, the scroll view delays handling
the touch-down gesture until it can determine if scrolling is the
intent. If the value is NO , the scroll view immediately calls
touchesShouldBegin:withEvent:inContentView:. The default
value is YES.
You'll have to (as you've mentioned) add the UIView containing the image and buttons to the actual UITableView. Embedding it in the scroll view will produce the undesired behavior that you're seeing.
I would recommend returning the UIView as the header view for the first section of your table view. You can do this by implementing the UITableViewDelegate method:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
If you maintain an IBOutlet to the view containing your image/labels, you can return it here.
this is same demo i hope its helps you from iphone sorce code library
http://developer.apple.com/library/ios/#samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html
thank you
I have a UITableView which is a subview of a UIView, then that UIView is a subview of a UIScrollView. How do I detect the touches that should scroll the UITableView?
The UITableView can get item selection events (a cell in the table is selected/tapped) just fine, except that you have to hold down on the cell before it fires. But I can't get the UITableView to scroll, its always the UIScrollView that reacts to the pan gesture.
Any help is greatly appreciated. Thanks in advance!
EDIT:
Solved, though I asked the wrong question. It does work by default as Roman K pointed out. I think the problem was related to having a part of the UITableView outside the bounds of the UIScrollView (the UITableView went over the bottom bounds of the UIScrollView). Setting it to correctly fit inside the UIScrollView fixed it.
Please, make sure that UIScrollView's properties delaysContentTouches and canCancelContentTouches are set appropriately. They control how UIScrollView instance passes touch information to its subviews. By default delaysContentTouches is set to YES. Also, make sure that, if you extended UIScrollView, touchesShouldBegin:withEvent:inContentView: allow touches in the subview.
Otherwise, UITableView scrolling should work by default in your scenario. If you create a test project with just the view hierarchy as described you will see that it is the case. So, compare the two and see what difference affects the scrolling.