ios*_*bie 2 xcode objective-c modalviewcontroller ios
我的任务是在一些现有的VC中添加新的简单通知模式视图.充其量,我想实现一个在当前视图中显示notificationVC的函数.
有很多类似的问题,但它们不适合我或需要代表,segues等.
谢谢,这就像我想要的:
如果要在另一个视图控制器上显示视图控制器,最简单的方法是将其modalPresentationStyle设置为UIModalPresentationOverFullScreen或UIModalPresentationOverCurrentContext.如果呈现的视图控制器的视图具有alpha小于1的背景颜色,则呈现视图控制器的视图将显示.使用您的示例,在您的呈现视图控制器中,您可以说:
- (void) presentNotificationViewController
{
NotificationViewController *notificationVC = [[NotificationViewController alloc] init];
notificationVC.titleText = @"My Notification Title";
notificationVC.image = image;
notificationVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
notificationVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:notificationVC animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
然后你NotificationViewController.m可以这样:
#import "NotificationViewController.h"
@interface NotificationViewController ()
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UILabel *notificationTitleLabel;
@property (weak, nonatomic) IBOutlet UIButton *dismissButton;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation NotificationViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.60];
self.contentView.layer.cornerRadius = 3.0;
self.notificationTitleLabel.text = self.titleText;
self.imageView.image = self.image;
self.dismissButton.layer.cornerRadius = 3.0;
self.dismissButton.layer.borderColor = [UIColor blackColor].CGColor;
self.dismissButton.layer.borderWidth = 2.0;
// etc.
}
- (IBAction)dismissPressed:(UIButton *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
Run Code Online (Sandbox Code Playgroud)
或者无论你想要什么.请注意,我将视图的背景颜色设置为半透明,而我有一个不透明的contentView,它充当实际的警报视图.contentView标签,按钮和图像视图作为子视图.此代码以及.xib,其中我使用约束设置我的UI,导致:
| 归档时间: |
|
| 查看次数: |
2416 次 |
| 最近记录: |