我希望在窗口上有一个视图,并且响应一条消息(按钮点击或菜单),我希望在其上方向下滑动另一个视图,并让第一个视图调整大小.
我想离开这个:
********************************** * * *--------------------------------* *| |* *| view 1 |* *| |* *--------------------------------* * * **********************************
对此:
********************************** * * *--------------------------------* *| view 2 |* *--------------------------------* *--------------------------------* *| view 1 |* *--------------------------------* * * **********************************
我不一定在寻找代码,从哪里开始的想法将不胜感激.
这适用于桌面应用.
CoreAnimation绝对是您最好的选择.自从我使用任何CA代码以来已经有一段时间了,但是类似于:
[UIView beginAnimations:@"slideOn" context:nil]; firstView.frame = shrunkFirstViewRect; // The rect defining the first view's smaller frame. This should resize the first view secondView.frame = secondViewOnScreenFrame; // This should move the second view on the frame. [UIView commitAnimations];
稍后,您可以使用以下命令返回单个视图:
[UIView beginAnimations:@"slideOff" context:nil]; firstView.frame = normalFirstViewRect; // The rect defining the first view's normal frame. This should expand the first view. secondView.frame = secondViewOffScreenFrame; // Move the second view off the screen [UIView commitAnimations];
编辑:以上代码适用于iPhone,我读了你的问题有点快.
在Mac上,您可能希望使用(类似地):
[NSAnimationContext beginGrouping]; [[NSAnimationContext currentContext] setDuration:1.0f]; // However long you want the slide to take [[firstView animator] setFrame:shrunkFirstViewRect]; [[secondView animator] setFrame:secondViewOnScreenFrame]; [NSAnimationContext endGrouping];