我为iPhone做了一些非常类似的事情。但校长应该非常相似。在下面的代码示例中,将UIView更改为NSView,依此类推。
首先,您需要一个处理细节和编辑之间交换的根视图控制器。
其中,有一个像这样的方法。传递到方法新旧视图是属于新旧视图控制器view
实例变量:
- (void) slideInNewViewFromRight:(UIView *)newView oldView:(UIView *)oldView remove:(BOOL)remove
{
UIView *superView = [oldView superview];
[superView insertSubview:newView belowSubview:oldView];
CGRect oldFrame = [oldView frame];
oldFrame.origin = CGPointMake(-kScreenWidth, 0.0f);
CGRect newFrame = [newView frame];
newFrame.origin = CGPointMake(kScreenWidth, 0.0f);
newView.frame = newFrame;
newFrame.origin = CGPointMake(0.0f, 0.0f);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:kSlideOffDuration];
[UIView setAnimationDelegate:self];
if (remove) {
[self setViewToRemove:oldView];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
}
[oldView setFrame:oldFrame];
[newView setFrame:newFrame];
[UIView commitAnimations];
}
的animationDidStop
委托方法将处理从superview
删除旧view
当它完成:
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[viewToRemove removeFromSuperview];
}
,不要忘了常量:
#define kScreenWidth 320.0f
#define kSlideInDuration 0.2f
有人可能是在那里THI为什么我没有使用UITabBarController
或UINavigationController
?答案是,由于我的视图控制器的非分层结构,在我的案例中都没有意义。实际上,我的网络更像。所以,我用自定义的根视图控制器来处理所有事情。
至于CATransition
,我从来没有用过它。我很想知道更多关于它的应用程序,以及它是否可以为这个问题提供更优雅的解决方案。
不幸的是,UIViews比NSView载入更多的功能。自从我从iPhone开发到Mac后,我实际上首先研究了您的方法。我不知道为什么它在Cocoa上更复杂:/ – Christoffer
这很令人沮丧。这是一个类似的问题,似乎有一个Mac解决方案http://stackoverflow.com/questions/726795/how-can-i-slide-a-view-in-and-out-of-a-window-in-a - 可可程序 –
你能否解释倒票 –