跟随 UICollectionViewCell
Follow a UICollectionViewCell
我有一个 UICollectionView
,它由单元格中的 UIImagePickerControl
按钮填充,我希望屏幕后跟集合视图末尾的单元格,但仍然允许用户滚动
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
NSString* imageString = [image toString];
Screen * screen = [[Screen alloc]init];
screen.imageData = imageString;
[self.project.screens addObject:screen];
long long rowid = [self saveNewImageForScreenToDb:screen];
[self updateTitle:@"" atRowId:rowid];
[self updateTask:@"" atRowId:rowid];
[self dismissViewControllerAnimated:_picker completion:^{
[_collectionView reloadData];
}];
NSIndexPath * indexPath = [[NSIndexPath alloc]initWithIndex:?];
[self.collectionView scrollToItemAtIndexPath: indexPath.row =?
atScrollPosition:UICollectionViewScrollPositionRight
animated:YES];
}
这是选择器的代码,选择器是我 'UICollectioView' 末尾的一个按钮。我必须插入什么 indexPath 才能让屏幕滚动到按钮所在的末尾
您会将所选图像添加到 NSMutableArray
。假设您的数组是 imagesArray
。将 collectionView
滚动到 NSMutableArray
的最后一个对象。尝试在 didFinishPickingImage
方法下添加此代码。
[_collectionView reloadData];
NSIndexPath *bottomIndexPath=[NSIndexPath indexPathForRow:imagesArray.count-1 inSection:0];
[self.collectionView scrollToItemAtIndexPath: bottomIndexPath atScrollPosition:UICollectionViewScrollPositionRight animated:YES];
我有一个 UICollectionView
,它由单元格中的 UIImagePickerControl
按钮填充,我希望屏幕后跟集合视图末尾的单元格,但仍然允许用户滚动
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
NSString* imageString = [image toString];
Screen * screen = [[Screen alloc]init];
screen.imageData = imageString;
[self.project.screens addObject:screen];
long long rowid = [self saveNewImageForScreenToDb:screen];
[self updateTitle:@"" atRowId:rowid];
[self updateTask:@"" atRowId:rowid];
[self dismissViewControllerAnimated:_picker completion:^{
[_collectionView reloadData];
}];
NSIndexPath * indexPath = [[NSIndexPath alloc]initWithIndex:?];
[self.collectionView scrollToItemAtIndexPath: indexPath.row =?
atScrollPosition:UICollectionViewScrollPositionRight
animated:YES];
}
这是选择器的代码,选择器是我 'UICollectioView' 末尾的一个按钮。我必须插入什么 indexPath 才能让屏幕滚动到按钮所在的末尾
您会将所选图像添加到 NSMutableArray
。假设您的数组是 imagesArray
。将 collectionView
滚动到 NSMutableArray
的最后一个对象。尝试在 didFinishPickingImage
方法下添加此代码。
[_collectionView reloadData];
NSIndexPath *bottomIndexPath=[NSIndexPath indexPathForRow:imagesArray.count-1 inSection:0];
[self.collectionView scrollToItemAtIndexPath: bottomIndexPath atScrollPosition:UICollectionViewScrollPositionRight animated:YES];