2014-03-26 20 views
0

我需要一個視圖來彈出並讓用戶登錄。我無法明顯地使用動作表,因爲他們只有按鈕。如何使UIView充當動作表?

所以我想要一個UIView上滑而不是。

我創建了UIView,名爲CustomModalView。

看來我需要像這樣的代碼:

- (IBAction)showTapped:(id)sender { 
    [UIView animateWithDuration:.5 animations:^{ 
    subView.frame=CGRectMake(0, 225, subView.frame.size.width, subView.frame.size.height); 
    }]; 
    } 

- (IBAction)hideTapped:(id)sender { 
    [UIView animateWithDuration:.5 animations:^{ 
    subView.frame=CGRectMake(0, 480, subView.frame.size.width, subView.frame.size.height); 
    }]; 
    } 

但我新的目標C,我不知道如何定製這個我自己的項目......我甚至不知道把這個代碼放在哪裏。任何幫助將不勝感激。

+0

您可以根據需要自定義UIView,然後根據需要放置UIButton。 –

+0

'presetnModelVieController'而不是視圖。 –

回答

1

簡單的方法是使用添加視圖UIActionSheet

[actionSheeet addSubview: subView]; 
+0

我讀過,你只能將按鈕放在操作表上 - 這是不是真的? – fewaf

+0

不,它不是真的。 UIButton是UIView的繼承。所以如果你把按鈕,那麼也UIView。 –

1

我假設你已經有其中加入CustomModalView像子視圖一個UIViewController。我重寫二方法上面是這樣的:

- (void)showLoginView{ 
    [UIView animateWithDuration:.5 animations:^{ 
    customModalView.frame=CGRectMake(0, 225, customModalView.frame.frame.size.width, customModalView.frame.frame.size.height); 
    }]; 
} 

- (void)hideLoginView{ 
    [UIView animateWithDuration:.5 animations:^{ 
    customModalView.frame.frame=CGRectMake(0, 480, customModalView.frame.frame.size.width, customModalView.frame.frame.size.height); 
    }]; 
} 

在UIViewController.m,調用[自我showLoginView]顯示否則

1

如果你需要的是一個用戶名和密碼的文本輸入一個簡單的登錄提示,以及登錄和取消按鈕,則可以使用UIAlertView。只需將其UIAlertViewStyle財產設置爲UIAlertViewStyleLoginAndPasswordInput即可。 如果您之前沒有使用過這些文件,請閱讀Apple的文檔UIAlertViewUIAlertViewDelegate

2

您可以使用操作表執行此操作。 首先在界面聲明uiactionsheet的屬性。在下面的例子中,我已經聲明瞭一個名爲countryActionSheet的屬性。

之後在IBaction中跟着代碼;

-(IBAction)popupView{// declare another actionSheet // 
UIActionSheet *actionSheet =[[UIActionSheet alloc]initWithTitle:@"Select Country"  delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil]; 

countryActionsheet=actionSheet;//equate both the actionSheets// 

actionSheet.actionSheetStyle= UIActionSheetStyleBlackTranslucent; 
countryPicker.dataSource=self; 
countryPicker.delegate=self; 

// Add your view with frame with respect to actionSheet// 

UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 400)]; 
imageView.image=[UIImage imageNamed:@"black background.png"]; 

UIButton *cancelBtn=[[UIButton alloc]initWithFrame:CGRectMake(200,20, 80, 30)]; 
[cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 
[cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
[cancelBtn addTarget:self action:@selector(cancelBtnPressed) forControlEvents:UIControlEventTouchUpInside];// create a method named cancelBtnPressed 
[cancelBtn setBackgroundImage:[UIImage imageNamed:@"Untitled 4.png"] forState:UIControlStateNormal]; 

UIButton *okBtn =[[UIButton alloc]initWithFrame:CGRectMake(40, 20, 80, 30)]; 
[okBtn setTitle:@"Done" forState:UIControlStateNormal]; 
[okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
[okBtn addTarget:self action:@selector(okBtnPressed) forControlEvents:UIControlEventTouchUpInside];// create method named okBtnPressed 
[okBtn setBackgroundImage:[UIImage imageNamed:@"Untitled 4.png"] forState:UIControlStateNormal]; 


[countryActionsheet addSubview:imageView]; 
[countryActionsheet addSubview:cancelBtn]; 
[countryActionsheet addSubview:okBtn]; 

[countryActionsheet showInView:self.view]; 
[countryActionsheet setBounds:CGRectMake(0, 0, 320, 400)];// frame of actionSheet 
} 

-(void)cancelbtnPressed{ 
    // write action 
} 

-(void)okBtnPressed{ 
    // write action 
} 

希望這可以幫助你;

+0

以上代碼中的countryPicker是什麼?... @ Abin George –