uicollectionview

Is there any way to know which collection view cell is at a specific point?

梦想与她 提交于 2019-12-24 01:51:35
问题 I have a CGPoint and I would like to know which cell from my collection view currently contains that point. Is there any simple way to do this or do I have to write my own method? 回答1: I haven't used UICollectionView s much, but there's a method that seems perfect: - (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point; The point you pass to the method has to be within the coordinate system of the collection view. You can do: CGPoint convertedPoint = [collectionView convertPoint:point

Slow UICollectionView with asynchronous loading

旧街凉风 提交于 2019-12-24 01:46:08
问题 I have an UICollectionView which loads images of the iPad's memory and displays them in a grid,like Apple's Photos app. The UICollectionViewCell loads thumbnails asynchronously: func setImage(img:String){ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { //load the image in the background let image = UIImage(contentsOfFile: img) //when done, assign it to the cell's UIImageView dispatch_async(dispatch_get_main_queue(), { if let imageView = self.imageView{

“targetContentOffset” UICollectionViewFlowLayout not working properly

会有一股神秘感。 提交于 2019-12-24 01:33:26
问题 I have a requirement to keep UICollectionViewCell center aligned in portrait mode. Final result should be like : animation I'm using this code to do this: override public func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint { var layoutAttributes: Array = layoutAttributesForElements(in: collectionView!.bounds)! if layoutAttributes.count == 0 { return proposedContentOffset } var firstAttribute:

'NSInvalidArgumentException' : attempt to scroll to invalid index path

自作多情 提交于 2019-12-24 01:15:16
问题 This is my code for animating the CollectionViewCustomCells. -(void)viewDidAppear:(BOOL)animated{ rowIndex = 0; [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(targetMethod) userInfo:nil repeats:YES]; } -(void)targetMethod { [self.offerCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:rowIndex inSection:1] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES]; rowIndex=(rowIndex<parserDataContentArrayForExhibitor.count

DecorationViews on UICollectionView are duplicated on every insert

对着背影说爱祢 提交于 2019-12-24 01:08:36
问题 I am trying to create a book shelf with an UICollectionView, not unlike the iBooks app. It works nicely, however whenever I insert a new item into the view (by calling insertItemsAtIndexPaths: ), the item is inserted correctly, but my shelf items (which are DecorationViews, subclasses of UICollectionReusableView ) are getting darker and darker, obviously being painted over and over again. However, if a call reloadData on the UICollectionView everything is painted correct. This is what I did

How to use a detail disclosure button in UICollectionViewCell?

走远了吗. 提交于 2019-12-24 00:44:20
问题 I am trying to use the detail disclosure button on the view controller pictured below (PhotoSearchViewController) to show a UIAlertController that shows the photo description from the ImageUrlItem. When I click the button, it shows that it was pressed, but the alert containing the description does not appear. My code for the ImageUrlItem: import Foundation import Firebase struct ImageUrlItem { //Should I add my description in here? let key: String let imageUrl: String let

Setting and changing width/height of UICollectionView cells with UICollectionViewLayout

假装没事ソ 提交于 2019-12-23 23:24:16
问题 I'm using drag and drop to drag images from google onto a collection view. The images are all supposed to have equal widths. After I scroll a bit, some of the cells look like they have equal widths, but some images are too big. The collectionView has a flow layout and horizontal scroll direction. In the following gif, the images start out as if they may have the same width(I can't really tell). When I drag an image in, they resize, and you can immediately see that the two on the left no

How to use SDWebImage in my project

百般思念 提交于 2019-12-23 20:16:40
问题 Iam using collectionview to load image.These images are loaded from url in background thread. Hence the scrolling is not smooth.The images in url get expired after seconds hence i want to update the image with new image.How can i use the SDWebImage to load image and make scrolling smooth? Can anyone please help me to solve this. 回答1: Use this code [YOUR_CELL_NAME.YOUR_IMAGE_NAME setImageWithURL:[NSURL URLWithString:@"IMAGE URL"] placeholderImage:[UIImage imageNamed:@"PLACEHOLDER IMAGE NAME"]]

AVPlayer inside of UICollectionViewCell stops playing when app enters background

我们两清 提交于 2019-12-23 18:51:11
问题 I have a local video file playing in a loop using AVPlayerLooper but whenever I press the home button (app enters background) and then reopen the app, the video has stopped playing. I also have an AVPlayerLooper inside of a simple view and not a collectionViewCell. To solve the issue on this view I simply call player.play() inside of applicationDidBecomeActive() . This does not work for the collectionViewCell. Have tried removing playerLayer before the app enters the background and adding it

UICollectionView - Autolayout with pinterest style layout

↘锁芯ラ 提交于 2019-12-23 18:18:29
问题 I am currently trying to build a pinterest style layout while having a dynamic height using autolayout (trying to stay away from manual calcuations of cell heights). I am currently aiming for iOS 9 and greater. I have seen brilliant examples of how to do a dynamic layout and a pinterest layout with calculations specific for each index but not with autolayout. Currently my thoughts are that the item would no its width, i.e. layout has x number of columns and an item could span y columns, so