2015-10-06 91 views
0

我使用這個偉大的STPopup: http://cocoadocs.org/docsets/STPopup/1.2.0/Classes/STPopupController.htmlSTPopupController的解除/關閉回調方法?

- (void)showPopupWithTransitionStyle:(STPopupTransitionStyle)transitionStyle rootViewController:(UIViewController *)rootViewController 
{ 
    STPopupController *popupController = [[STPopupController alloc] initWithRootViewController:rootViewController]; 
    popupController.cornerRadius = 4; 

    popupController.transitionStyle = transitionStyle; 
    [popupController presentInViewController:self]; 
    //[popupController dismissWithCompletion:^{NSLog(@"Dismissed!");}]; 

} 

- (IBAction)btnClick:(id)sender { 
    [self showPopupWithTransitionStyle:STPopupTransitionStyleSlideVertical rootViewController:[ad new]]; 
} 

這是工作的罰款,到目前爲止,但我想,當彈出窗口關閉的執行代碼。我怎樣才能做到這一點?

Thx!

回答

1

代替

[popupController presentInViewController:self]; 

使用下面的代碼,

[popupController presentInViewController:self completion:^{ 
    NSLog(@"Dismissed!"); 
//execute your code when popup is closed, here! 
}]; 

編輯: 您可以使用以下解僱彈出後執行代碼的方法。

- (void)dismissWithCompletion:(void (^) (void))completion 
+0

當彈出完成雨後春筍般冒出來,這是隻執行該'completion'代碼。並且*不在通過點擊交叉按鈕關閉時。 – user3550458

0

視圖控制器,其在彈出控制器所示的​​viewWillDisappear & viewDidDisappear,當彈出控制器被駁回將被調用。

0

在我看來最好的解決方案。

- (void)didMoveToParentViewController:(UIViewController *)parent 
{ 
    if (![parent isEqual:self.parentViewController]) { 
     NSLog(@"Popup close!"); 
    } 
} 

但它僅適用於iOS5的+