我正在攻击multicanvas example。我想修改它,以便在显示新的目标视图时触发某个事件,即在完成transitionFromView方法时。
我知道我可能会在transitionFromView方法的完成块中触发一些事件,但我想知道是否存在现有的回调机制。
我已尝试在目标画布中实现以下功能,但在切换视图时似乎没有调用:
- (void)viewDidAppear{
NSLog(@"my event");
}
还有其他回调我不知道吗? 谢谢。
答案 0 :(得分:1)
尝试使用以下方法:
-(void)viewDidAppear:(BOOL)animated {}
-(void)viewDidDisappear:(BOOL)animated {}
注意:这是您在方法名称中遗漏的:(BOOL)animated {}
部分。
我下载了MultiCanvas示例,并设置了每个画布的标题,如下所示(将A更改为B和C):
-(void)setup {
self.title = @"WorkSpaceA";
//... the rest of the setup code as per the example
}
我还为每个画布添加了两种方法:
-(void)viewDidAppear:(BOOL)animated {
C4Log(@"%@ %@",self.title,NSStringFromSelector(_cmd));
}
-(void)viewDidDisappear:(BOOL)animated {
C4Log(@"%@ %@",self.title,NSStringFromSelector(_cmd));
}
然后我得到了以下日志:
//at launch
[C4Log] WorkSpaceA viewDidAppear:
//then I tapped button B
[C4Log] WorkSpaceB viewDidAppear:
[C4Log] WorkSpaceA viewDidDisappear:
//then I tapped button A
[C4Log] WorkSpaceA viewDidAppear:
[C4Log] WorkSpaceB viewDidDisappear:
//then I tapped Button C
[C4Log] WorkSpaceA viewDidAppear:
[C4Log] WorkSpaceB viewDidAppear:
[C4Log] WorkSpaceC viewDidAppear:
[C4Log] WorkSpaceA viewDidDisappear: