通知中心-在音乐软件中的应用

来源:互联网 发布:淘宝交易额 英文 编辑:程序博客网 时间:2024/04/30 03:05

首先要先设置一个继承与UIView的一个类,类中包含歌手图片,歌曲,歌手,上一曲和下一曲暂停的view  --

PlayView



然后在appdelegate中设置一个属性,属性的类属于

PlayView

 

在-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

 self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

     [_window release];


 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

    [center addObserver:self selector:@selector(musicChange:) name:@"change" object:nil];


    [center addObserver:self selector:@selector(hidden:) name:@"hidden" object:nil];

    [center addObserver:self selector:@selector(didHidden:) name:@"didHidden" object:nil];

    self.playView = [[PlayView alloc] initWithFrame:CGRectMake(0, self.window.frame.size.height - 60, self.window.frame.size.width, 75)];

    self.playView.backgroundColor = [UIColor cyanColor];

    self.playView.alpha = 0.5;

    self.playView.userInteractionEnabled = YES;


    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];

    

    [self.playView addGestureRecognizer:tap];




}

- (void)tap:(UITapGestureRecognizer *)tap

{

       

    self.play  = [PlayViewController sharePlayVC];

    

    [_homeview presentViewController:self.play animated:YES completion:^{

    

    }];

}


- (void)hidden: (NSNotification*)noti

{

    self.playView.hidden = NO;

    

}

- (void)didHidden:(NSNotification *)noti

{

    self.playView.hidden = YES;

}


-(void)musicChange:(NSNotification *)noti

{

    self.playView.detail = noti.object;

    

    NSLog(@"%@",noti.object);

    

}



// 在播放页面的反回按钮的触发函数中载入

- (void)ReturnButton: (UIButton*)button

{

    NSDictionary *notidic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"hidden" object:@"dddd" userInfo:notidic];

    

        [self dismissViewControllerAnimated:YES completion:^{

            

        }];

    

}


// 这样的设置可以使我们能达到想要的目的
点击底部的view弹出播放界面,播放界面会隐藏掉刚才的播放的view

0 0
原创粉丝点击