IOS - 圆形走投无路的临时警报 - 如何实施?

时间:2014-05-12 14:10:10

标签: ios objective-c

我想对uitableviewcontroller实施临时警报,以通知用户他们的数据已保存。

我可以使用uiAlertView执行此操作 - 但出于美观原因,最好实现类似于IOS7中用于显示音量控制等任务的圆形角落淡入/淡出警报视图 - 如本照片所示 - < / p>

enter image description here

这是IOS7课吗?我无法找到任何信息(可能是因为我不知道它叫什么!),还是我需要扩展uiAlertView来复制这个功能?

4 个答案:

答案 0 :(得分:2)

不,这不是本地iOS 7子类,但是它有很多实现。一个示例是DTAlertViewCXAlertViewSDCAlertView。检查一下。

答案 1 :(得分:2)

如果您只想要volume-thingy类型的行为,请不要搜索太多。它很容易在家中滚动,全屏大小的图像视图大部分是透明的,并且在它的中心有一个圆角消息矩形,如果你愿意,它是半透明的。然后构建一个方便的方法来显示/隐藏动画......

- (void)setAlertHidden:(BOOL)hidden animated:(BOOL)animated {

    UIImageView *alertImageView = [self alertImageView];
    BOOL currentlyHidden = alertImageView.alpha == 0.0;
    if (currentlyHidden == hidden) return;

    NSTimeInterval alpha = (hidden)? 0.0 : 1.0;
    NSTimeInterval duration = (animated)? 0.3 : 0.0;

    [UIView animateWithDuration:duration animations:^{
        alertImageView.alpha = alpha;
    } completion:^(BOOL finished) {
        // if we showed the alert, hide it after 3 seconds
        // you can make this duration a parameter
        if (!hidden) {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                [self setAlertHidden:YES animated:YES];
            });
        }     
    }];
}

除此之外你需要的只是懒洋洋地构建图像视图......

- (UIImageView *)alertImageView {
    UIImageView *alertImageView = (UIImageView *)[self.view viewWithTag:999];
    if (!alertImageView) {
        alertImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
        alertImageView.image = [UIImage imageNamed:@"fullscreen-volume-looking-thing.png"];
        alertImageView.tag = 999;
        [self.view addSubview:alertImageView];
    }
    return alertImageView;
}

意识到它并不完全符合您的需求,但这很容易粘贴在一起。这是屏幕尺寸透明背景上的音量......

enter image description here

答案 2 :(得分:0)

这是一个快速实现的子视图,可以做你想做的事情

#import "BellAlert.h"

@implementation BellAlert

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        UIImageView *bell = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Bell.png"]];
        bell.frame = CGRectMake(0, 0, 50, 50);
        bell.center = self.center;
        [self addSubview:bell];
    }
    return self;
}

- (void)drawRect:(CGRect)rect {

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1].CGColor);

    CGContextMoveToPoint(context, 5, 0);
    CGContextAddLineToPoint(context, 95, 0);
    CGContextAddArcToPoint(context, 100, 0, 100, 5, 10);
    CGContextAddLineToPoint(context, 100, 95);
    CGContextAddArcToPoint(context, 100, 100, 95, 100, 10);
    CGContextAddLineToPoint(context, 5, 100);
    CGContextAddArcToPoint(context, 0, 100, 0, 95, 10);
    CGContextAddLineToPoint(context, 0, 5);
    CGContextAddArcToPoint(context, 0, 0, 5, 0, 10);

    CGContextFillPath(context);
}

@end

如果您想要更复杂的功能,可以实现公共属性和协议

如果你想查看它的工作,请在GitHub上查看... https://github.com/eharo2/BellAlert

答案 3 :(得分:0)

  

出于美学原因,最好实施某些东西   类似于IOS7中使用的圆形角落淡入/淡出警报视图

任何视角的圆角都非常容易:

someView.layer.cornerRadius = 5.0;

使用Core Animation制作视图淡入淡出也很简单。例如,如果要淡入someView,请将其alpha属性设置为0,然后将其设置为1的动画:

someView.alpha = 0.0;
[UIView animateWithDuration:1.0 animations:^{
    someView.alpha = 1.0;
}];

使用这些工具,你会发现很容易推出自己的Apple版本。

相关问题