【问题标题】:ios code for CATransition works only the first time?CATransition 的 ios 代码仅在第一次工作?
【发布时间】:2011-11-02 02:30:03
【问题描述】:

我使用此代码在 ios sdk 中从一个视图转换到另一个视图,但它只在第一次工作,当我返回上一个视图时它不起作用,尽管代码被触发......

UIView *currentView = self.viewController1.view;

// get the the underlying UIWindow, or the view containing the current view view
UIView *theWindow = [currentView superview];

// remove the current view and replace with myView1
[currentView setHidden:TRUE];//hide previous view diladi to tabviewcontroller
self.viewController1=[[MyFriendProfile alloc] initWithNibName:@"MyFriendProfile" bundle:nil];
[theWindow addSubview:self.viewController1.view];
[currentView setHidden:FALSE]; 
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView2"];

感谢任何帮助!

【问题讨论】:

  • 我刚刚试用了您的样品,它看起来适合我。我唯一做的就是不使用隐藏视图,而只是使用 addSubview: 方法并且不要忘记调用 removeFromSuperview 方法,当您从第二个视图返回到第一个视图时

标签: objective-c ios catransition


【解决方案1】:

我在这里找到了答案是代码...

//获取viewcontroller1视图

UIView *currentView = self.viewController1.view;

// get the the underlying UIWindow, or the view containing the current view view
UIView *theWindow = [currentView superview];

// remove the current view and replace with myView1
[currentView setHidden:TRUE];//hide previous view diladi to tabviewcontroller


MyFriendProfile *test1=[[MyFriendProfile alloc] initWithNibName:@"MyFriendProfile" bundle:nil];


[theWindow addSubview:test1.view];


// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-17
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    相关资源
    最近更新 更多