ios 模态转场问题,使用中介者,使用 storyboard

KevinZ123 2017-07-31 11:11:25
使用中介者集中管理 UI
使用转场的时候碰到
presentModalViewController:controller animated:方法已失效,
应该用什么方法来替代吗?
具体该怎么写
(代码中 // 转场到调色板视图)

中介者 CoordinatingController.h
#import <Foundation/Foundation.h>

#import "CanvasViewController.h"
#import "PaletteViewController.h"
#import "ThumbnailViewController.h"

typedef enum
{
kButtonTagDone,
kButtonTagOpenPaletteView,
kButtonTagOpenThumbnailView
} ButtonTag;

@interface CoordinatingController : NSObject
{
//@private
// CanvasViewController *canvasViewController_;
//UIViewController *activeViewController_;
}

@property (nonatomic, assign) UIViewController *activeViewController;
@property (nonatomic, strong) CanvasViewController *canvasViewController;

+ (CoordinatingController *) sharedInstance;

-(IBAction) requestViewChangeByObjectHit:(id)object;

@end


CoordinatingController.m
//
//
// CoordinatingController.m
// TouchPainterByKevin v1.0
//
// Created by zhengkevin on 2017/7/31.

#import "CoordinatingController.h"
#import <UIKit/UIKit.h>

@interface CoordinatingController ()

- (void) initialize;

@end

@implementation CoordinatingController

@synthesize activeViewController,canvasViewController;

static CoordinatingController *sharedCoordinator = nil;

- (void) initialize
{
canvasViewController = [[CanvasViewController alloc] init];
activeViewController = canvasViewController;
}

#pragma mark -
#pragma mark CoordinatingController Singleton Implementation

// 这是一个严格的单利模式,线程安全,堵截了自身的 alloc 和 init 方法创建不同的对象
+ (CoordinatingController *) sharedInstance
{
if (sharedCoordinator == nil)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedCoordinator = [[super allocWithZone:NULL] init];
});

// 创建第一个View Controller,并保持这个单例
[sharedCoordinator initialize];
}

return sharedCoordinator;
}

+ (id) allocWithZone:(NSZone *)zone
{
return [self sharedInstance];
//return [CoordinatingController sharedInstance];
}

- (id) copyWithZone:(NSZone*)zone
{
//return self;
return [CoordinatingController sharedInstance];
}

#pragma mark -
#pragma mark A method for view transitions

-(IBAction) requestViewChangeByObjectHit:(id)object{

if ([object isKindOfClass:[UIBarButtonItem class]])
{
//NSLog(@"%@",[object class]);
//NSLog(@"%li",[object tag]);

switch ([(UIBarButtonItem *)object tag])
{

case kButtonTagOpenPaletteView:
{
NSLog(@"%li 现在在 PaletteView",(long)[(UIBarButtonItem *)object tag]);

// 加载调色板视图
PaletteViewController *controller = [[PaletteViewController alloc] init];

// 转场到调色板视图
//[canvasViewController presentModalViewController:controller animated:YES];


//[canvasViewController presentViewController:controller animated:YES completion:nil];

//[canvasViewController.storyboard instantiateViewControllerWithIdentifier:@"Palette"];

[canvasViewController presentedViewController];
[controller presentingViewController];
//[canvasViewController presentViewController:controller animated:YES completion:^(void) {}];



// 设置活跃视图为调色板视图
activeViewController = controller;
}
break;
case kButtonTagOpenThumbnailView:
{
NSLog(@"%li 现在在 ThumbnailView",(long)[(UIBarButtonItem *)object tag]);
// 加载文件缩略浏览图ThumbnailViewController
ThumbnailViewController *controller = [[ThumbnailViewController alloc] init];


// 转场到文件缩略浏览视图ThumbnailViewController
//[canvasViewController presentModalViewController:controller animated:YES];


[canvasViewController.storyboard instantiateViewControllerWithIdentifier:@"Palette"];

// 设置活跃视图为ThumbnailViewController
activeViewController = controller;
}
break;
default:
// just go back to the main canvasViewController
// for the other types
{
// The Done command is shared on every
// view controller except the CanvasViewController
// When the Done button is hit, it should
// take the user back to the first page in
// conjunction with the design
// other objects will follow the same path
//[canvasViewController dismissModalViewControllerAnimated:YES];

[canvasViewController dismissViewControllerAnimated:YES completion:nil];

// set the activeViewController back to
// canvasViewController
activeViewController = canvasViewController;
}
break;
}
}else
{
//[canvasViewController dismissModalViewControllerAnimated:YES];

[canvasViewController dismissViewControllerAnimated:YES completion:nil];



// set the activeViewController back to
// canvasViewController
activeViewController = canvasViewController;
}
}

@end
...全文
174 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
KevinZ123 2017-07-31
  • 打赏
  • 举报
回复
重点是我不会这个模态转场 如果再指导下这个中介者模式就更好呢

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧