【发布时间】:2014-09-12 07:36:01
【问题描述】:
我正在开发一个应用程序,我需要一个包含许多图像的图库。我想要做的是当用户点击/单击任何图像时,它应该将该图像旋转 90 度,如果用户将任何图像拖动到任何其他图像的顶部,那么这些图像应该切换它们的位置(或者我们可以说交换的地方)。
解释:
A B C
D E F
假设上面是我画廊的图像,所以如果用户将图像 A 拖到图像 E 的顶部,那么画廊应该看起来像这样
E B C
D A F
我正在使用 UICollectionView 制作我的画廊。这是我到目前为止所做的。
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageArray = [NSArray arrayWithObjects:@"angry_birds_cake.jpg", @"creme_brelee.jpg", @"egg_benedict.jpg", @"full_breakfast.jpg", @"green_tea.jpg", @"ham_and_cheese_panini.jpg", nil];
[self.collectionView registerClass:[ClosetsCell class] forCellWithReuseIdentifier:@"ClosetsCell"];
[self.collectionView setPagingEnabled:YES];
// Configure layout
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(100, 100)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[self.collectionView setCollectionViewLayout:flowLayout];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.imageArray count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
// Setup cell identifier
static NSString *cellIdentifier = @"ClosetsCell";
ClosetsCell *cell = (ClosetsCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamed:[self.imageArray objectAtIndex:indexPath.row]];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checked.png"]];
// Return the cell
return cell;
}
-(CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 1;
}
-(CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 4;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"ClosetsCell";
ClosetsCell *cell = (ClosetsCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
printf("Selected View index=%d",indexPath.row);
cell.imageView.transform = CGAffineTransformMakeRotation(M_PI_2);
}
但我认为 CGAffineTransformMakeRotation 不适用于我的案例。
【问题讨论】:
标签: ios objective-c iphone uiimageview uicollectionview