ios - 我怎样才能像 Play Music 应用程序一样弹出消息

标签 ios iphone objective-c cocoa-touch uiview

我想在他们的应用程序中添加像谷歌播放音乐应用程序这样的栏。我想使用与他们正在做的相同的动画效果。因此,任何人都可以指导我是否有任何开源代码可以在应用程序中添加此功能,或者我需要手动编写所有代码,任何指南都会有所帮助,我在网上搜索但没有找到。

enter image description here

最佳答案

@interface ViewController ()
@property (nonatomic, weak) UILabel *popupLabel;
@end

@implementation ViewController

- (UILabel *)popupLabel
{
    if( !_popupLabel ) {
        CGFloat height = 44.0;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,
                                                                   self.view.bounds.size.height - height,
                                                                   self.view.bounds.size.width,
                                                                   height)];
        label.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
        label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        label.alpha = 0.0;
        [self.view addSubview:label];

        _popupLabel = label;
    }
    [self.view bringSubviewToFront:_popupLabel];
    return _popupLabel;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [self performSelector:@selector(showWithMessage:) withObject:@"1 song added to playlist" afterDelay:2.0];

}

- (void)showWithMessage:(NSString *)message
{
    self.popupLabel.text = message;
    [UIView animateWithDuration:1.0 animations:^{
        self.popupLabel.alpha = 1.0;
    }];
}

- (void)hide
{
    [UIView animateWithDuration:1.0 animations:^{
        self.popupLabel.alpha = 0.0;
    }];
}

关于ios - 我怎样才能像 Play Music 应用程序一样弹出消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20260506/

相关文章:

ios - 使用 xib 创建 UICollectionViewCell 子类

ios - Theos:如何使用 block 参数 Hook 方法? (CDUnknownBlockType)

ios - 同一个 AVCaptureSession 中的多个 AVCaptureVideoDataOutput

iphone - Textview 中心文本对齐 IOS 7

iphone - 将 UIWebView 中的图像放入 UIImageView 中

ios - 无法将 JSONValue 写入 NSDictionary - JSON 框架无法正常工作

objective-c - 可以从watchkit观看运行视频吗?

ios - 如何使用 Swift 将文本复制到剪贴板/粘贴板

android - Appcelerator Studio 无法在 Mac 上检测到有效的 iOS 或 Android SDK

iphone - InAppSettingsKit UIWebView