簡體   English   中英

如何在繼續之前強制用戶與UIView進行交互?

[英]How to force user interaction with UIView before continuing?

在StackOverflow上的許多其他人的幫助下,當用戶點擊某個人臉或人物時,我終於可以顯示個人資料界面UIView。

但是,在我的應用程序(iOS 6,Xcode 4.6)中,我還需要彈出窗口視圖將索引返回給調用的ViewController,因為下一步是使用該索引刷新屏幕。 例如,用戶單擊主ViewController中的頂面或圖像,並且應該看到一個允許用戶瀏覽然后選擇另一個圖像的彈出窗口。 當配置文件屏幕被解除時(從彈出窗口中的取消或選擇),主屏幕應該使用用戶在彈出框中選擇的照片更新照片。

現在,我正在使用委托方法將用戶在彈出窗口中的選擇返回到調用ViewController,然后才解除自身。 問題是當我運行我的代碼時,在調用ViewController移動到下一步並嘗試使用配置文件屏幕在被解除之前更新的變量之前,popover甚至都沒有出現。 這是一個問題,因為變量是垃圾,直到用戶在彈出框中執行某些操作來更新它。

代碼的工作原理如下。 首先,用戶點擊主ViewController中的內容:

- (IBAction)handleTapFace1:(UITapGestureRecognizer *)sender
{
    NSLog(@"Face 1 tapped!");
    [self showProfileView:0];

    if (returnedSwitchIndex != NO_SWITCH)
    {
        // Animate switch
        [self performVisualSwitch: selectedFaceIndex to:returnedSwitchIndex];
    }
}

showProfileView是我在其中啟動彈出窗口配置文件窗口的功能,其中包含點擊面的詳細信息,以及瀏覽每個面以獲取替換面的功能。 彈出窗口包含一個取消UIButton,一個Switch UIButton,詳細信息。

-(void) showProfileView: (int) tappedIndex
{
    UIStoryboard *storyboard = self.storyboard;

    ProfileViewController *profViewController = [storyboard instantiateViewControllerWithIdentifier:@"ProfileView"];

    // Pass the parameters profView needs to display
    profViewController.currentIndex = tappedIndex;
    profViewController.turnIndex = 0; // <-- TODO: test value

    NSMutableArray* members = [[NSMutableArray alloc] init];
    ... load array with candidate faces ...

    profViewController.faces = [[NSArray alloc] initWithArray:members];

    [self addChildViewController:profViewController];

    profViewController.view.frame = CGRectMake(0, 0, 320, 548);
    [self.view addSubview: profViewController.view];
    profViewController.view.alpha = 0;
    [profViewController didMoveToParentViewController:self];

    NSLog(@"Self located at: %@", NSStringFromCGPoint(self.view.frame.origin));
    NSLog(@"Frame located at: %@", NSStringFromCGPoint(profViewController.view.frame.origin));

    // popup
    [UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^
     {
         profViewController.view.alpha = 1;
     }
                     completion:nil];

    // I previous tried to return a value here, that also failed
    //return profViewController.switchIndex;

    // trying to force redisplay before calling ViewController can proceed
    [profViewController.view setNeedsDisplay];
}

我想我想問的是......“為什么在showProfileView的調用者向前移動之前,UIView / popover窗口不能出現?” 和“在調用ViewController超出showProfileView行並開始使用returnedSwitchIndex之前,如何強制用戶與彈出的UIView或UIViewController進行交互?” 也許我的委托解決方案不是這樣的,但是我如何從顯示的UIView中返回一些東西?

謝謝你的幫助。 抱歉有這些問題。

PS>我選擇使用動畫UIView方法,因為我需要調用ViewController繼續存在並顯示在后台,並且它還包含一個NSTimer,當用戶使用彈出視圖時向下滴答。 沒關系,希望讓調用ViewController在那里,並讓它的NSTimer繼續運行,但是在視圖有機會實際出現並迫使用戶與它交互之前,它在showProfileView之外的代碼中前進是完全不好的。取消按鈕或瀏覽並按另一張臉上的切換按鈕)

我不太明白你的要求。 但你必須明白UIView操作是一次性完成的。

所以:

用戶觸摸臉部:

- (IBAction)handleTapFace1:(UITapGestureRecognizer *)sender
{
    NSLog(@"Face 1 tapped!");
    [self showProfileView:0];
}

然后你把回調放在另一個方法中:

- (void)goAhead
{
    if (returnedSwitchIndex != NO_SWITCH)
    {
        // Animate switch
        [self performVisualSwitch: selectedFaceIndex to:returnedSwitchIndex];
    }
}

最后,在需要時(例如,在用戶與popover交互之后)調用goAhead方法:

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    [self goAhead];
}

拉這個東西

if (returnedSwitchIndex != NO_SWITCH)
{
    // Animate switch
    [self performVisualSwitch: selectedFaceIndex to:returnedSwitchIndex];
}

進入自己的方法,並在用戶選擇或取消時將該方法設置為目標。 那應該工作。

要讓UIButton調用您的方法,您可以執行以下操作:

[button addTarget:self
           action:@selector(userDidChoose)
 forControlEvents:UIControlEventTouchUpInside];

暫無
暫無

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

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