iOS - 方向改变 - 视错觉或元素移动?

时间:2012-07-13 09:43:43

标签: iphone ios ipad animation orientation

当我转向时,我想知道iOS中的动态动画。例如。在我的iPad上,动画在菜单中看起来非常“真实”。元素(应用程序,文件夹,底座,背景图像,状态栏,......)似乎以完美的审美方式滑动到正确的位置...
但是在App Store我发现了一个偏差,因为应用程序列表有另一种安排。
我的一个大问题:orientationChangeAnimation是一个光学错觉还是它真的如此动态?在App Store中,它看起来像实际的屏幕正在转动,同时它的alpha值正在减小,并且更改的屏幕的横向/纵向方向正在进行相同的反转(在增加alpha值的同时转向相同的轴)。

2 个答案:

答案 0 :(得分:1)

是的,这实际上很容易做到,而且我在很多应用程序上做过类似的事情。如果您想复制该功能,可以执行以下操作:

在willRotateToInterfaceOrientation方法或viewWillLayoutSubviews方法中,您可以执行以下任一操作:

//Fade out
[UIView animateWithDuration:0.3 animations:^ {
    yourController.view.alpha = 0.2;
}];

//Fade In
[UIView animateWithDuration:0.3 animations:^ {
    yourController.view.alpha = 1.0;
}];

//Fade out fade in
[UIView animateWithDuration:0.15 animations:^ {
    yourController.view.alpha = 0.2;
}];

[UIView animateWithDuration:0.15 animations:^ {
    yourController.view.alpha = 1.0;
}];

干杯,

萨姆

答案 1 :(得分:1)

确实,Springboard确实可以移动物体(如底座),它也可以交叉淡化物品(就像大多数应用程序图标一样)。

由于在旋转期间在动画块内部调用viewWillLayoutSubviewswillRotateToInterfaceOrientation,因此您可以简单地为动画属性(如alpha和frame)指定新值。除非你想要明确控制时间,否则不需要明确的animateWithDuration:animations:个调用;在轮换期间,iOS会自动为您设置动画。

例如,在下面的代码中,红色和绿色方块在屏幕中央交叉淡入淡出,蓝色方块在旋转过程中在左上角和顶部中心之间移动。

CGRect b = self.view.bounds;
self.greenLabel = [[UILabel alloc] initWithFrame:CGRectMake(b.size.width / 2 - 50, b.size.height / 2 - 50, 100, 100)];
self.greenLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
self.greenLabel.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.greenLabel];

self.redLabel = [[UILabel alloc] initWithFrame:self.greenLabel.frame];
self.redLabel.autoresizingMask = self.greenLabel.autoresizingMask;
self.redLabel.backgroundColor = [UIColor redColor];
[self.view addSubview:self.redLabel];

self.blueLabel = [[UILabel alloc] init];
self.blueLabel.backgroundColor = [UIColor blueColor];
[self.view addSubview:self.blueLabel];

...

- (void)viewWillLayoutSubviews {
  if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
    self.greenLabel.alpha = 0;
    self.redLabel.alpha = 1;
    self.blueLabel.frame = CGRectMake((self.view.bounds.size.width - 100) / 2, 20, 100, 100);
  } else {
    self.greenLabel.alpha = 1;
    self.redLabel.alpha = 0;
    self.blueLabel.frame = CGRectMake(20, 20, 100, 100);
  }
}