I'm having problems figuring out a way to determine when UICollectionView is/has finished animating.
I currently have a UICollectionView that animates between two subclassed flow layouts using setCollectionViewLayout:animated:
The animation looks great, however, I'm having some undesired behaviour if a user selects a cell during the animation.
I'm looking at ignoring the cell 'selection' by returning NO through the UICollectionViewDelegate method collectionView:shouldSelectItemAtIndexPath: - however - I cannot figure out a reliable test to see if the collection view is currently animating.
Any ideas?
Try checking that there are no animation keys.
BOOL isAnimating = myView.layer.animationKeys.count > 0
Related
I am adding an infinitely repeating CALayer animation to the cells in a UICollectionView. For some reason, whenever I return to the app after sending it to the background, or return to the view controller after pushing another one on top of it, the animations are removed from the cells. Please let me know if you have any idea why this might be.
When switch app or ViewController, the system will let animations on layer stop(complete), so you can set removedOnCompletion to NO(default is YES), it will work.
I have a UIScrollView, and what I need, is that when the user stops dragging it, the scrollview stops scrolling to.
Sometimes it works, but sometimes, the scroll continues when the pression is released.
I tried a lot of things with the scrollView.tracking, or with delegate methods like scrollViewDidScroll, or scrollViewDidEndDecelerating, etc. But for the moment, I didn't found anything !
I also tried UIPageControl but I need my scroll view to stop every 50 pixel.
Thank you for your time and your help !
You need to impelement this method (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate the decelerate parameter means should scroll view stop immediately or not. Try to use decelerationRate property to set the needed rate.
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
I'm trying to customize the three20 TTPhotoViewController so that the first & last images cannot be dragged.
Example of what I am trying to prevent.
https://plus.google.com/photos/109413514618904450093/albums/5730490807945885537?authkey=CMTi6OfqhLS2NQ
The image shows the currently selected image has been dragged upwards. This behaviour does not occur on the central images only the first & last.
The code responsible for this behaviour is in the TTScrollView. If it was a uiscrollview I would just set bounces to NO.
Can anyone tell me how I can achieve this result?
I think the issue is in TTScrollView:resistPageEdges but my hacking has left me nowhere
TTPhotoViewController delegates TTScrollViewDelegate.
TTScrollViewDelegate has -(void)scrollViewWillBeginDragging:(TTScrollView *).
TTScrollView has (void)cancelTouches.
Therefore, you can write this in your own subclass of TTPhotoViewController.
- (void)scrollViewWillBeginDragging:(TTScrollView *)scrollView {
[scrollView cancelTouches];
}
Every time a user try to drag, it will cancel any active touches and resets everything to an untouched state.
I'm working on an an app that updates both a UITableView and a UIScrollView. I like how UITableView updating works. As I add, remove, or update items, I call insertRowsAtIndexPaths:withRowAnimation:, reloadRowsAtIndexPaths:withRowAnimation:, and deleteRowsAtIndexPaths:withRowAnimation: as appropriate. However, updating the UIScrollView has turned out to be more of a challenge.
So how can I do it? My UIScrollView contains images, and I want to be able to insert, update, and remove individual images -- with animation -- efficiently and smoothly, and perhaps in random order. How does one do this sort of thing?
As an example, I have code like this in my UIScrollViewDelegate implementation for adding a new image:
if (newImageindex == currentImageIndex) {
[scrollView setNeedsDisplay];
[scrollView setContentOffset:portalView.contentOffset animated:YES];
} else if (newImageIndex < currentImageIndex) {
currentImageIndex++;
CGPoint offset = portalView.contentOffset;
offset.x += portalView.frame.size.width;
portalView.contentOffset = offset;
}
This is close, I think, but not quite right. I end up with the images added, but the UIScrollView seems to scroll to a position before the first image in the view. If I start scrolling it by hand, the first image appears. It's like it's scrolled to position -1 in my images.
The example may not help to highlight my problem much, but surely it's a common need to dynamically rejigger the images appearing in a UIScrollView. What's the state of the art on this?
A UIScrollView is not so specialized and structured as a UITableView. The former is a generic view that scrolls and zooms anything you put in it, and you can put any subviews into it anywhere, whereas the latter is made especially to display lists of cells stacked on top of each other.
So the answer is: you need to animate the subviews in the scrollview yourself. There are various libraries like Three20 which provide frameworks for creating more advanced views, you'll need to use a suitable component from one of those or roll your own.