2014-02-24 25 views
0

我有一個自定義用戶界面,當用戶單擊屏幕的一部分時,我想要像鍵盤一樣顯示。我看過例子,但是他們引用UIView的方法,這些方法似乎並不存在(也許是因爲我有Starter許可證?),例如UIView.beginAnimations不在那裏。Xamarin - 如何在另一個頂部查看,如鍵盤

有沒有人有Xamarin(即MonoTouch)的例子?

我想要我的UI片段顯示,並滾動現有的視圖,以便該字段正確可見。

回答

1

UITextViewUITextFieldinputView屬性,它可以讓你實現你所需要的。設置視圖,將其設置爲輸入視圖,一旦用戶創建文本視圖或文本字段第一響應者,您的視圖就會出現。 iOS7有UIInputView類,您可以繼承該類,以實現與鍵盤類似的背景視圖。

+0

我可以創建一個普通視圖控制器,並使用其觀點的InputView(允許我這樣做視覺XCode中)還是我必須要完全做到這一點通過代碼? –

+1

@DrissZouak如果您使用XIB文件,您基本上只定義一個視圖,而不是視圖控制器,而故事板定義視圖控制器。最好爲視圖創建子類,但可以使用視圖控制器的視圖作爲輸入視圖,是的。 –

0

爲什麼不創建視圖並將其放置在可見視圖之外。當你想展示它時,你只需將其移動到可見區域即可。這樣你也可以添加動畫。

NSLayoutConstraint *yourHiddenViewYConstraint; 

- (void)viewDidLoad 
{ 
    [self.view addSubView:yourHiddenView]; 
    [yourHiddenView setHidden:YES]; 
    UIView *selfView = self.view 
    yourHiddenView.translatesAutoresizingMaskIntoConstraints = NO; 
    // add your needed constraints, other than the one below 
    yourHiddenViewYConstraint = [NSLayoutConstraint constraintWithItem:yourHiddenView 
                attribute:NSLayoutAttributeTop 
                relatedBy:NSLayoutRelationEqual 
                 toItem:selfView 
                attribute:NSLayoutAttributeTop 
                multiplier:1.0 
                 constant:0]; 
    [selfView addConstraint:yourHiddenViewYConstraint]; 
    yourHiddenViewYConstraint.constant += self.view.frame.size.height; 
} 

顯示它在需要的時候:

- (void)showView 
{ 
    [yourHiddenView setHidden:NO]; 
    dispatch_async(dispatch_get_main_queue(), ^(void) { 
     [self changeConstraint:yourHiddenViewYConstraint withConstant:-self.view.frame.size.height]; 
    }); 
} 

- (void)changeConstraint:(NSLayoutConstraint *)constraint withConstant:(CGFloat)constant 
{ 
    constraint.constant += constant; 

    void (^anim)(void) = ^{ 
     [self.view layoutIfNeeded]; 
    }; 

    [UIView animateWithDuration:0.5 animations:anim completion:nil]; 
} 
+0

這將創建一個模糊的佈局。您沒有爲隱藏視圖提供足夠的約束。此外,完全在頂端 - 對於手頭的任務來說太複雜了。 –

+1

忽略了我關於Xamarin和C#的觀點,我很難得到在Xamarin中工作的例子。 –

相關問題