我有一个集合视图,我声明了不同的项目大小
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
FeedItem *item = [_imagesLinkArray objectAtIndex:indexPath.row];
return CGSizeMake(250, 200*item.sizeFactor);
}
Run Code Online (Sandbox Code Playgroud)
当正在重复使用单元格时,正在使用已重新collectionView:cellForItemAtIndexPath:
计划的项目大小而不是指定的项目大小来呈现该单元格sizeForItemAtIndexPath:.
有任何想法吗?
我有一个UICollectionView,我想为每个单元格添加动画.
目前我正在使用
for(UICollectionView *cell in collectionView.visibleCells){
//add animation to cell here
}
Run Code Online (Sandbox Code Playgroud)
但是,这仅将动画应用于可见单元格,并且只要向下滚动并且单元格不再可见,动画就会停止.
我如何循环遍历所有细胞UICollectionView?
我有一个垂直UICollectionView的每个单元占用整个self.view.frame我可以轻松向上滑到页面到下一个单元格,但我想按下一个按钮做同样的事情.
我尝试过使用:
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
和:
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
他们工作但他们暂时"白出"当前的Cell以呈现nextCell,而刷卡在转换过程中显示两个单元格.
理想情况下我想使用:
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
但我不知道如何访问nextCell indexPath...我试过:
NSIndexPath *nextIndexPath = [_collectionView indexPathForItemAtPoint:CGPointMake(25, (_collectionView.frame.size.height-25)*(_currentIndexRowForCellOnScreen+1))];
Run Code Online (Sandbox Code Playgroud)
哪里_currentIndexRowForCellOnScreen是indexPath.row对的UICollectionView的屏幕上的首次亮相:
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
但当我把它放入:
- (NSIndexPath *)indexPathForCell:(UICollectionViewCell *)cell
Run Code Online (Sandbox Code Playgroud)
它在第一个Cell之后返回NULL,并且没有动画....
任何方向将不胜感激.感谢您的时间.
objective-c uiscrollview ios uicollectionview uicollectionviewcell
当你在iPhone的照片应用程序(或几乎所有其他应用程序中)中点击照片时,我想复制完全相同的didSelect animation/segue,其中照片从单元格本身放大到模态视图控制器,并最小化到任何地方被解雇时属于网格.
我试过谷歌搜索但找不到任何关于此的文章.
iphone objective-c ios uicollectionview uicollectionviewcell
我已经实现了一个UICollectionView保存UIImageView对象列表.
我希望用户在触摸图片时使用特定的网址访问YouTube.
但我不知道如何为每个UICollectionViewCell添加触摸侦听器:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell: PhotoCell = collectionView.dequeueReusableCellWithReuseIdentifier("PhotoCell", forIndexPath: indexPath) as PhotoCell
cell.loadImage(thumbnailFileURLs[indexPath.row], originalImagePath: originalFileURLs[indexPath.row])
return cell
}
Run Code Online (Sandbox Code Playgroud)
我的PhotoCell类有一个成员变量,用于保存youtube的URL.
对于每个PhotoCell对象,按下时,我希望我的应用程序将用户发送到youtube.com网站或APP(如果已安装)
我想UIImageView在里面添加一个动画,UICollectionViewCell所以我想出了这段代码:
import UIKit
class MainViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
var items:[String] = ["one", "two", "three", "four"]
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(red: 220/255, green: 220/255, blue: 220/255, alpha: 1.0)
self.view.addSubview(self.collectionView)
}
lazy var collectionView:UICollectionView = {
var cv = UICollectionView(frame: self.view.bounds, collectionViewLayout: self.flowLayout)
cv.delegate = self
cv.dataSource = self
cv.bounces = true
cv.alwaysBounceVertical = true
cv.autoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth
cv.registerClass(CustomCell.self, forCellWithReuseIdentifier: "cell")
cv.backgroundColor = UIColor(red: 220/255, green: 220/255, blue: 220/255, alpha: 1.0)
return …Run Code Online (Sandbox Code Playgroud) 我在我的子类中使用UIStackView布局.我正在使用iOS SDK 9.2UILabelsUICollectionViewCell
如果我text在出列标签时不更新标签,则集合视图的滚动是平滑的.但是,如果我在将它们text出列时更新它们,则滚动速度非常慢.
我做了一个非常小的演示来显示问题,在设备(不是模拟器)上运行.您可以创建一个新的空项目并用以下内容替换ViewController.swift:
import UIKit
class ViewController: UIViewController {
override func loadView() {
view = UIView()
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: 100, height: 200)
let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
collectionView.registerClass(Cell.self, forCellWithReuseIdentifier: "Cell")
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.dataSource = self
view.addSubview(collectionView)
let constraints = ["H:|-[collectionView]-|",
"V:|[collectionView]|"
].flatMap { NSLayoutConstraint.constraintsWithVisualFormat($0, options: [], metrics: nil, views: ["collectionView": collectionView])
}
NSLayoutConstraint.activateConstraints(constraints)
}
}
extension ViewController: UICollectionViewDataSource {
func collectionView(collectionView: …Run Code Online (Sandbox Code Playgroud) 我有一个FollowVC和FollowCell设置与集合视图.我可以使用以下代码正确地将所有数据显示到我的uIcollection视图单元格中,没有任何问题.
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCellWithReuseIdentifier("FollowCell", forIndexPath: indexPath) as? FollowCell {
let post = posts[indexPath.row]
cell.configureCell(post, img: img)
if cell.selected == true {
cell.checkImg.hidden = false
} else {
cell.checkImg.hidden = true
}
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,我还可以使用以下代码选择和取消选择多个图像
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
if deletePressed == true {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! FollowCell
cell.checkImg.hidden = false
} else {
let post = posts[indexPath.row]
performSegueWithIdentifier(SEGUE_FOLLOW_TO_COMMENTVC, sender: post)
}
} …Run Code Online (Sandbox Code Playgroud) 我在我的iPad应用程序中使用collectionView.我使用了继承UICollectionViewFlowLayout类的自定义布局类.
我正在使用水平滚动方向.问题是,每当我们使用滚动进行集合视图时,有时候单元格会消失.我调试了代码,发现在创建单元格后的数据源方法中,其隐藏属性自动获得ON.
我尝试使用下面的线,但它无法正常工作
cell.hidden = NO
Run Code Online (Sandbox Code Playgroud)
我在下面的方法也使绑定更改的布局无效.
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
但我仍面临着问题.对此有何解决方案?
提前致谢.
ios ×10
objective-c ×4
swift ×3
uiscrollview ×2
animation ×1
ios6 ×1
iphone ×1
uiimageview ×1
uistackview ×1