Iphone iOS-方向改变-视错觉还是元素移动?

Iphone iOS-方向改变-视错觉还是元素移动?,iphone,ios,ipad,animation,orientation,Iphone,Ios,Ipad,Animation,Orientation,当我旋转方向时,我想知道iOS中的动态动画。例如,在我的iPad上,菜单中的动画看起来非常“真实”。元素(应用程序、文件夹、停靠点、背景图像、状态栏等)似乎以完美的美学方式滑到了正确的位置… 但在应用商店中,我发现了一个偏差,因为应用列表有另一种安排。我的大问题是:方向变化动画到底是一种视觉错觉,还是真的如此动态?在App Store中,看起来实际屏幕正在旋转,同时其alpha值正在减小,并且更改的屏幕的横向/纵向方向正在进行相同的反转(在相同的轴上旋转,同时增加alpha值).是的,这其实很容

当我旋转方向时,我想知道iOS中的动态动画。例如,在我的iPad上,菜单中的动画看起来非常“真实”。元素(应用程序、文件夹、停靠点、背景图像、状态栏等)似乎以完美的美学方式滑到了正确的位置…

但在应用商店中,我发现了一个偏差,因为应用列表有另一种安排。
我的大问题是:方向变化动画到底是一种视觉错觉,还是真的如此动态?在App Store中,看起来实际屏幕正在旋转,同时其alpha值正在减小,并且更改的屏幕的横向/纵向方向正在进行相同的反转(在相同的轴上旋转,同时增加alpha值).

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

在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;
}];
干杯


Sam

事实上,Springboard确实可以移动东西(比如dock),它还可以交叉淡出项目(比如大多数应用程序图标)

由于旋转期间在动画块内调用了
viewWillLayoutSubviews
willrotatetointerfaceooritation
,因此您只需将新值指定给可设置动画的属性,如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);
  }
}
例如,在下面的代码中,红色和绿色方块在屏幕中心交叉淡入,蓝色方块在旋转过程中在左上角和中上角之间移动

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);
  }
}