많은 이미지가 포함 된 갤러리가 필요한 앱을 개발 중입니다. 그리고 내가하고 싶은 일은 사용자가 이미지를 90도 회전해야하는 이미지를 탭/클릭하고 사용자가 다른 이미지의 상단으로 이미지를 드래그하면 해당 이미지가 해당 위치로 전환되어야합니다 (또는 스왑 서로의 장소).터치시 이미지 회전 및 다른 이미지 위로 이미지 드래그
설명 : 이미지 E의 상단에 사용자가 드래그 이미지 A가 다음 갤러리이
EBC과 같아야합니다 그래서 만약 DEF
위의 가정
ABC
내 갤러리의 이미지입니다
DAF
내 갤러리를 만들기 위해 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이 내 사례에서 작동하지 않는다고 생각합니다.
'cell.imageView.transform = CGAffineTransformConcat (cell.view.transform, rotation);'이 줄을 편집 한 것을 볼 수 있습니다. 그러나 customCell에는 view라는 객체가 없으므로이 셀을 시도했습니다. .imageView.transform = CGAffineTransformConcat (cell.imageView.transform, rotation);'그러나 여전히 행운이 없습니다. – Zac24
당신이 옳았 어, 편집 했어! 그 줄은'cell.imageView.transform = CGAffineTransformConcat (cell.transform, rotation); '입니다. 저는 독자적으로 몇 가지 테스트를했는데 작동합니다. – Starscream
'ClosetsCell * cell = (ClosetsCell *) [collectionView cellForItemAtIndexPath : indexPath];'에 의해'ClosetsCell * cell = (ClosetsCell *) [collectionView dequeueReusableCellWithReuseIdentifier : cellIdentifier forIndexPath : indexPath];를 대체하십시오. 셀이 이미 보이기 때문에,'cellForItem'으로 가져올 수 있습니다. 새로운 것을 instanciate 할 필요가 없습니다! 그것은 작동합니다. – Starscream