带有ARC的presentModalViewController

时间:2012-11-13 22:24:00

标签: objective-c ios xcode

我发现这段代码用于良好的转换:

http://srooltheknife.blogspot.co.uk/2012/03/custom-transition-animation-for-modal.html

问题是它使用'modal'而我的程序使用ARC,因此在iOS 6.0中不推荐使用modal。

只有两行使用模态,所以我从 -

更改了它们
TransitionController.m:
[self dismissModalViewControllerAnimated:NO];
to:
[self dismissViewControllerAnimated:NO completion:Nil];

[self presentModalViewController:modalViewController animated:NO];
to:
[self presentViewController:modalViewController animated:NO completion:nil];

我执行它:

FirstPage.m:
@implementation FirstPage
{
    TransitionController *tran;
}

- (IBAction)StartGame:(id)sender
{

    if (! self.mainPage)
    self.mainPage = [[MainGameDisplay alloc] initWithNibName:nil bundle:nil];

    [tran presentModalViewController:self.mainPage withPushDirection:kCATransitionFromBottom];
}

StartGame是一个按钮。该程序运行完美,没有错误,但是当我点击按钮时没有任何反应。


更新:

FirstPage.h:
#import <UIKit/UIKit.h>
#import "MainGameDisplay.h"
#import <QuartzCore/QuartzCore.h>
#import "TransitionController.h"
@interface ViewController : Engine
{ }
- (IBAction)StartGame:(id)sender; //Action connection ID.
@property(nonatomic, readwrite) MainGameDisplay *mainPage;

FirstPage.m:
@implementation ViewController
{
    TransitionController *tran;
}
- (IBAction)StartGame:(id)sender {
    if (! self.mainPage)
    self.mainPage = [[MainGameDisplay alloc] initWithNibName:nil bundle:nil];
    tran = [[TransitionController alloc] initWithNibName:Nil bundle:Nil];
    [tran presentModalViewController: self.mainPage withPushDirection:kCATransitionFromBottom];
}
  • 单击“StartGame”按钮时,将推送当前视图 左边是完全相同的视图。
  • 过渡期间视线略微褪色/发光。
  • 方法中使用的方向与过渡方向不同。例如,'kCATransitionFromBottom'实际上是从左侧推送的视图。
  • 每按一次按钮输出:“警告:尝试显示其视图不在窗口层次结构中!”

0 个答案:

没有答案