我試圖複製在屏幕中間,即顯示撰寫新鳴叫報警。我試圖用自定義的UIAlertView
來複制它,但是這需要很多子類化,但是我不認爲它可能只是一個簡單的UIViewController
,它顯示在主視圖上......需要來自其他iOS開發人員的專業思想。
謝謝。
我試圖複製在屏幕中間,即顯示撰寫新鳴叫報警。我試圖用自定義的UIAlertView
來複制它,但是這需要很多子類化,但是我不認爲它可能只是一個簡單的UIViewController
,它顯示在主視圖上......需要來自其他iOS開發人員的專業思想。
謝謝。
在iPad上:
您可以用UIViewController做到這一點。
UIModalPresentationFormSheet
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))
像:
UIViewController *viewC = [[UIViewController alloc] init];
viewC.view.frame = //set the frame;
viewC.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:viewC animated:YES completion:nil];
在iPhone:
你可以這樣做使用UIView。
您可以使用下面的代碼執行此操作:
在你的界面聲明屬性
@property (nonatomic, strong) UIView *views;
//添加視圖
- (void) showView
{
UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 35)];
UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(remove)];
toolbar.items = [NSArray arrayWithObject:bar];
_views = [[UIView alloc] initWithFrame:CGRectMake(0, -300, self.view.bounds.size.width, self.view.bounds.size.height/3)];
[_views addSubview:toolbar];
[_views setBackgroundColor:[UIColor grayColor]];
[self.view addSubview:_views];
[UIView animateWithDuration:0.7
delay:0.0
options:UIViewAnimationCurveLinear
animations:^{
_views.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height/3);
}
completion:^(BOOL yes){
NSLog(@"YO");
}];
[UIView commitAnimations];
}
//刪除視圖
- (void)remove
{
[UIView animateWithDuration:0.7
delay:0.0
options:UIViewAnimationCurveLinear
animations:^{
_views.frame = CGRectMake(0, -500, self.view.bounds.size.width, self.view.bounds.size.height/3);
}
completion:^(BOOL yes){
NSLog(@"YA");
}];
[UIView commitAnimations];
}
我擺弄了視圖控制器的框架,但它總是在整個視圖上顯示,而不是顯示爲主視圖控制器的疊加層。 – Souljacker
@ Ravin455:你設定了框架嗎? –
@ Ravin455:檢查樣式[here](http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html) –
屏幕在中間?這不是一個UIAlertView ...它應該是一個自定義的UIView。那麼,如果是用於推文,你是否應該使用iOS SDK中的Twitter API? – Larme
不,我用它來做別的事,是的,我認爲這將是一個UIView,但是你知道如何實現它嗎? – Souljacker