我有一个模仿照片应用程序的应用程序,它显示一张缩略图表,表示用户点击过的相册。旋转发生时,我无法模仿此窗口的动画。供您参考我在谈论的窗口如下:如何在缩略图视图中模仿照片应用程序的旋转
我能够得到最终结果转了罚款(即动画完成后,一切正常),然而,我的轮换看起来不如照片应用程序。照片应用程序实际上看起来像是在旋转窗口,您几乎不会注意到照片可以重置自己。在我的,你可以看到缩略图移动,看起来不太好。
有没有人有线索的照片应用程序在做什么?是否有可能加快动画速度,或者可能使它在中间变得模糊不清,因此你无法看到发生了什么?我的代码如下:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
else
{
for (UIButton *photoButton in [cell subviews])
{
[photoButton removeFromSuperview];
}
}
NSInteger photosPerRow;
if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
{
photosPerRow = 4;
}
else
{
photosPerRow = 6;
}
CGRect frame = CGRectMake(4, 2, 75, 75);
for (int i = [indexPath row] * photosPerRow; i < (([indexPath row] * photosPerRow) + photosPerRow) && i < [[self photos] count]; i++)
{
[[photos objectAtIndex:i] setFrame:frame];
[cell addSubview: [photos objectAtIndex:i]];
frame.origin.x = frame.origin.x + frame.size.width + 4;
}
return cell;
}
那么这里就是我如何动画在我的tableview控制器:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
[self.tableView reloadData];
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
更新:嗯,我已经试过了很多。到目前为止,我的所有代码都切换到了滚动视图,然后在发生旋转时尝试使缩略图呈现如下动画效果:淡出缩略图,将其移至新位置,然后淡入。当然,我只用UIThumbViews需要移动的东西。我得出的结论是,苹果必须使用两种观点才能将它们取消。一个视图与旧的一组缩略图视图,然后旋转新的一组缩略图视图。有任何想法吗?
我可以保证你的照片应用程序将不会被使用'UITableView'。我会用'UIScrollView'来做这件事,然后当你旋转的时候,你移动个别图像的框架,然后它应该看起来很平滑。 – mattjgalloway 2012-01-03 20:09:43
我同意mattjgalloway。如果我是你,我会继承UIScrollView的子类,并创建一个方法将一行的numberOfThumbnailPerRow和索引作为输入,并返回一个带CGPoints的NSValue数组作为每个方块的原点(缩略图)。 – Canopus 2012-01-04 14:18:59
你绝对不使用UIScrollView,你使用UITableView,所以它只会加载出现在屏幕上的缩略图,并将已经使用过的单元出列。当苹果为你做这件事时,没有意义实现所有这些功能。噢,旋转可以用两行完成,如果你用tableview实现它而不是scrollview。 – 2012-02-08 00:29:31