我的应用程序中有一个UICollectionView,每个单元格都是UIImageView和一些文本标签.问题是当我让UIImageViews显示他们的图像时,滚动性能很糟糕.它远不如UITableView的滚动体验,甚至没有UIImageView的相同UICollectionView.
我几个月前发现了这个问题,似乎找到了答案,但它是用RubyMotion编写的,我不明白.我试着看看如何将它转换为Xcode,但由于我从未使用过NSCache,所以有点难.海报上有还指出了这里关于实施,除了他们的解决方案的东西,但我不知道在哪里把这些代码要么.可能是因为我不理解第一个问题的代码.
有人能帮助将其翻译成Xcode吗?
def viewDidLoad
...
@images_cache = NSCache.alloc.init
@image_loading_queue = NSOperationQueue.alloc.init
@image_loading_queue.maxConcurrentOperationCount = 3
...
end
def collectionView(collection_view, cellForItemAtIndexPath: index_path)
cell = collection_view.dequeueReusableCellWithReuseIdentifier(CELL_IDENTIFIER, forIndexPath: index_path)
image_path = @image_paths[index_path.row]
if cached_image = @images_cache.objectForKey(image_path)
cell.image = cached_image
else
@operation = NSBlockOperation.blockOperationWithBlock lambda {
@image = UIImage.imageWithContentsOfFile(image_path)
Dispatch::Queue.main.async do
return unless collectionView.indexPathsForVisibleItems.containsObject(index_path)
@images_cache.setObject(@image, forKey: image_path)
cell = collectionView.cellForItemAtIndexPath(index_path)
cell.image = @image
end
}
@image_loading_queue.addOperation(@operation)
end
end
Run Code Online (Sandbox Code Playgroud)
UIImage *productImage = [[UIImage alloc] …Run Code Online (Sandbox Code Playgroud) performance objective-c rubymotion uicollectionview uicollectionviewcell
我正在尝试将UICollectionView显示在一个模态显示的视图控制器中.该应用适用于iPad iOS 7.
我已经创建了UIViewController的子类(带有一个nib),并添加如下:
MyViewController *controller = [[MyViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self presentViewController:navController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
这个视图控制器是我的UICollectionView的委托和dataSource所以我已经将UICollectionViewDataSource和UICollectionViewDelegate添加到标头中.
我将一个UICollectionView放入nib并为MyViewController添加了一个插座:
@property (strong, nonatomic) IBOutlet MyCollectionView *collectionViewController;
Run Code Online (Sandbox Code Playgroud)
我在MyViewController的viewDidLoad中添加了这个:
self.collectionViewController.dataSource = self;
self.collectionViewController.delegate = self;
Run Code Online (Sandbox Code Playgroud)
我还在MyViewController中添加了以下内容:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSLog(@"Items in section: %d", itemsArray.count); // returns correct amount
return itemsArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForItemAtIndexPath %@", indexPath); // returns as expected
static NSString *identifier = @"MyCell";
[self.collectionViewController registerClass:[MyCollectionCell …Run Code Online (Sandbox Code Playgroud) ipad ios uicollectionview uicollectionviewcell uicollectionviewlayout
我有一个UICollectionView支持水平和垂直滚动.每个集合视图单元都是它的子类,UICollectionViewCell它们是从包含UIButton's,UITableView甚至是另一个的NIB加载的UICollectionView.他们都在里面TPKeyboardAvoidingScrollView.
滚动在水平和垂直方向都可以完美地工作,但它不会在个人元素上接收触摸事件UICollectionViewCell.当我触摸任何元素时,说一个按钮是其中的一部分UICollectionViewCell,那么我得到的就是didSelectItemAtIndexPath事件UICollectionViewDelegate- 我无法将任何触摸事件传递到集合视图单元格的其中一个子视图上.
我已经将单元格的宽度(UICollectionViewCell)设置为等于UICollectionView的宽度,并且我试图使用包含在该单元格内的UILabel完全相同的事情.我认为下面的代码正好解释了我想要实现的目标.所以我在这里阅读了一些问题以及一些教程,但我仍然不确定如何实现这一目标.
在几个问题中它说的是使用collectionViewLayout但我真的在如何在我的代码中使用它.有任何想法吗?谢谢!
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("myCell", forIndexPath: indexPath) as LocationViewCell
cell.locationLabel.text = "Hello there!"
// Set cell & label width to 100%
let collectionViewWidth = self.collectionView.bounds.size.width
cell.frame.size.width = collectionViewWidth // Works
cell.locationLabel.frame.size.width = collectionViewWidth // Does NOT
Run Code Online (Sandbox Code Playgroud)
所以我添加了以下内容:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
// Set cell width to 100%
let collectionViewWidth = self.collectionView.bounds.size.width
return CGSize(width: collectionViewWidth, height: 35)
}
Run Code Online (Sandbox Code Playgroud)
发生的情况是,加载视图时,UILabel的宽度仍然很小.如果我转到另一个视图,然后返回,那么它是100%.所以我必须在viewDidLoad() …
ios uicollectionview uicollectionviewcell uicollectionviewlayout swift
我试图实现的效果是一种粘性标题单元格.对我来说,粘性细胞漂浮在其他细胞的顶部是很重要的.有点像这样:
????????????
? ?
? Cell 0 ?
? ??
?????????????
? Cell 4 ?
? ?
????????????
????????????
? ?
? Cell 5 ?
? ?
????????????
????????????
? ?
? Cell 6 ?
? ?
????????????
Run Code Online (Sandbox Code Playgroud)
单元格4,5和6通常是可见的,我正在构建UICollectionViewFlowLayout子类中单元格0的属性layoutAttributesForElementsInRect:.我所做的只是调用超级实现,确定我需要添加哪个单元格然后构造UICollectionViewLayoutAttributes(forCellWithIndexPath:).然后我将zIndex它设置为1(默认为0).
我得到的问题是UICollectionView似乎总是忽略了zIndex
????????????
? ?
? Cell 0 ?
?????????????
?? ?
? Cell 4 ?
? ?
????????????
????????????
? ?
? Cell 5 ?
? …Run Code Online (Sandbox Code Playgroud) 我创建了一个UICollectionView像这样的图像的应用程序:
添加了两个手势:
第一个(向上)将擦除单元格.
第二个(向下)将更新单元格(获取CoreData的新数据).功能很好,但没有动画.iOS有一个非常酷的动画拖动单元格,单元格消失.
我很快就是动画的初学者,所以当它变得有点失落时.
我的问题是:如何添加占据整个单元格的动画?
我在网站上阅读了一些答案,但都是在Object-C中(就像这样).
有人能帮我吗?
我有一个从故事板创建的UICollectionView,
我希望视图中每行有3个项目.我设法使用以下方法:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(collectionView.frame.size.width/3.6 , (collectionView.frame.size.height-100)/2);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我有6个项目,我有2行,每个3项.但是,当我有4个项目时,它将显示2行,每行2个项目.
是否可以将它们显示为2行,第一行包含3个项目,第二个包含1个?
objective-c ios uicollectionview uicollectionviewcell uicollectionviewlayout
预设,
我有collectionViewFlowLayout子类
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
return YES;
}
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *arr = [super layoutAttributesForElementsInRect:rect];
BBLog(@"ARRA:%@", arr);
for (UICollectionViewLayoutAttributes *attr in arr) {
if (CGAffineTransformIsIdentity(attr.transform)) {
attr.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);
}
}
return arr;
}
Run Code Online (Sandbox Code Playgroud)
CollectionView旋转到倒置滚动
self.collectionView.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);
Run Code Online (Sandbox Code Playgroud)
但即使jus使用本机collectionViewFlowLayout而没有子类化,也就是git这个错误
问题
我在聊天中有两条消息,但是当在底部滚动(通常是顶部)消失第二项时.
给定rect的layoutAttributesForElementsInRect为两个indexPaths 0-0和0-1返回两个属性,但委托方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
仅调用indexPath 0-0
这里的图片
更新 所以我发现为什么会发生 - 这个行代码
attr.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);
Run Code Online (Sandbox Code Playgroud)
看看是否删除转换
ios uicollectionview uicollectionviewcell uicollectionviewlayout uicollectionviewdelegate
我有一个包含多个部分的 UICollectionView。每个部分都有一个 HeaderView(UICollectionReusableView 类型)和多个单元格(UICollectionViewCell 类型)。
每个标题都有一个隐藏/显示按钮,用于隐藏/显示单元格。在任何时候,即使标题下的所有单元格都折叠/隐藏,标题也不会消失。
+------------------------+
| A Header [HIDE] |
| [Cell A] [Cell B] |
| [Cell c] [Cell D] |
| -----------------------|
| B Header [HIDE] |
| [Cell A] [Cell B] |
| [Cell c] [Cell D] |
| |
+------------------------+
Run Code Online (Sandbox Code Playgroud)
如果单击“A Header”的隐藏按钮,设计将如下所示:
+------------------------+
| A Header [SHOW] |
| -----------------------|
| B Header [HIDE] |
| [Cell A] [Cell B] |
| [Cell c] [Cell D] |
+------------------------+
Run Code Online (Sandbox Code Playgroud)
我读过手风琴菜单,但它似乎与 TableView 一起使用。快速制作简单的手风琴 TableView?
我还尝试重新加载 …
我有一个UICollectionView,它在网格中显示图像但是当我快速滚动时,它会暂时在单元格中显示错误的图像,直到从S3存储器下载图像,然后显示正确的图像.
我之前在SO上看到过与此问题有关的问题和答案,但没有一个解决方案适合我.let items = [[String: Any]]()API调用后填充字典.我需要细胞从废弃的细胞中丢弃图像.现在有一种令人不快的形象"跳舞"效果.
这是我的代码:
var searchResults = [[String: Any]]()
let cellId = "cellId"
override func viewDidLoad() {
super.viewDidLoad()
collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(MyCollectionViewCell.self, forCellWithReuseIdentifier: cellId)
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! MyCollectionViewCell
let item = searchResults[indexPath.item]
cell.backgroundColor = .white
cell.itemLabel.text = item["title"] as? String
let imageUrl = item["img_url"] as! String
let url = URL(string: imageUrl) …Run Code Online (Sandbox Code Playgroud) uicollectionview ×10
ios ×7
swift ×3
objective-c ×2
accordion ×1
animation ×1
events ×1
ipad ×1
performance ×1
rubymotion ×1
subview ×1
swift3 ×1
uikit ×1