簡體   English   中英

取消modalViewController后移動ViewController的視圖

[英]Moving view of ViewController after modalViewController dismissed

我有兩個ViewController:A和B。A是B的委托人。我要向A展示B,當我解散B時,我試圖移動A的視圖。我在委托中設置了一些方法來偵聽何時B被撤消以嘗試移動視圖。 這是我現在使用的,當B被解散時,但它不起作用。 我該如何工作?

[self dismissViewControllerAnimated:YES completion:^{
    NSLog(@"view dismissed");
    [self moveViews:self];
}];

- (IBAction)moveViews:(id)sender
{
    [UIView animateWithDuration:0.5
                     animations:^{
                         self.view.center = CGPointMake(160, 250);
                         //self.tableView.center = CGPointMake(160, -100);
                         self.addView.center = CGPointMake(160, 240);
                     }
                     completion:^(BOOL finished){}];
}

查看moveViews方法,您並沒有將視圖從一個視圖控制器移動到另一個。 您正在移動視圖的位置。 問題在於,被解雇的視圖控制器將不再是屏幕的一部分,因此將不可見。 我的建議是實現iOS 5 UIViewController包含並將添加的視圖控制器添加為另一個視圖控制器的子視圖控制器。 其原因是因為模態視圖控制器(控件,動作目標和模型)中包含的信息是模態呈現視圖控制器的一部分。 查看UIViewController類的文檔以及此處提到的包含:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

我認為問題是,您在這里稱為[self moveViews:self]; 視圖B上的方法。

在B中有一個id(例如,名為sender)屬性。

進行轉換時,將B中的sender屬性設置為A。

呼叫

    [self dismissViewControllerAnimated:YES completion:^{
    NSLog(@"view dismissed");
    [self.sender performSelector:@selector(moveViews)];
}];

那么B將被解散,並在A上調用moveViews方法。

在A中你有一個方法

    - (void)moveViews
{[UIView animateWithDuration:0.5
                     animations:^{
                         self.view.center = CGPointMake(160, 250);                        
      }
                     ];
}

應該工作,玩得開心

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM