ios - 对特定事件发表看法

标签 ios objective-c

我想创建一种“警报 View ”,例如通知用户他已禁用定位服务等。

由于此“警报 View ”仅出现在特定事件中,因此考虑了两种方法,因此目标是创建类似的东西: enter image description here

V1:

使用方法:

- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;

然后我必须为 viewcontroller 中的每个 Assets 设置 zPostion,从而确定在哪里设置“警报 View ”。因为它应该是最重要的。而且我必须在代码中创建完整的 View 。

V2:

是在 Storyboard中创建“警报 View ”加上设置特定约束并在运行时更改约束

编辑:

@implementation OHAlertWindow
// Initialize the UIWindow subclass and put a UILabel inside it
- (id)init {
    if(self = [super init]) {
        CGRect navigationBarFrame;
        CGRect statusBarFrame;
        UILabel *messageLabel;

        statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
        navigationBarFrame = CGRectMake(statusBarFrame.origin.x, statusBarFrame.origin.y,
                                        statusBarFrame.size.width, statusBarFrame.size.height + 50);
        messageLabel = [[UILabel alloc] init];
        [messageLabel setTextColor:[UIColor whiteColor]];
        [messageLabel setTextAlignment:NSTextAlignmentCenter];
        [self setWindowLevel:UIWindowLevelAlert]; // THIS IS IMPORTANT!!
        [self setAlpha:0.0f];
        [self setHidden:NO];
        [self setFrame:statusBarFrame];
        [self addSubview:messageLabel];
    }
    return self;
}

// Use singleton pattern so we only need one instance of the class
// throughout the whole app
+ (OHAlertWindow *)sharedInstance {

    static OHAlertWindow *_sharedInstance = nil;

    static dispatch_once_t oncePredicate;

    dispatch_once(&oncePredicate, ^{
        _sharedInstance = [[OHAlertWindow alloc] init];
    });

    return _sharedInstance;
}
- (void)showWithMessage:(NSString *)message {
    [UIView animateWithDuration:1.f animations:^{
        [self setAlpha:1.0f];
    }];
}

@结束

@implementation LaaxHomeViewController
-(void)viewDidLoad{
    [[OHAlertWindow sharedInstance]showWithMessage:@"test"] ;
}
@end

最佳答案

如果您使用的是导航 Controller ,UINavigationItem 具有用于在导航栏按钮上方显示附加文本的 prompt 属性。

    self.navigationItem.prompt = "Location services are disabled"

enter image description here

关于ios - 对特定事件发表看法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451586/

相关文章:

php - iOS - Swift 中的密码加密

objective-c - 你如何为 Mac OS X 编写程序?

jquery - 将数据从 objective-C/cocoa 发布到 .NET WebAPI

ios - 如何在xamarin中查看sqlite数据库

ios - UITableViewCell 子类,滚动前高度错误

ios - 从另一个 View Controller 访问数组数据

ios - BFTASK中的方法即使完成任务也会被延迟

objective-c - 未知的Objective-C错误“架构x86_64的 undefined symbol ”,一切似乎正常

ios - AppDelegate 中的应用程序 didFinishLaunching 是否总是在打开应用程序更新后被调用?

ios - 如何在 Firebase 中删除具有多个子对象的对象?