29,031
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
#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
// 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