//获得当前屏幕亮度 light = [UIScreen mainScreen].brightness; light = 0.5f; //直接赋值或者使用set方法皆可 [UIScreen mainScreen].brightness = light;
MPMusicPlayerController *mpVC = [MPMusicPlayerController applicationMusicPlayer]; //获得系统当前音量 voice = _mpVC.volume; voice = 0.5f; //改变系统音量 _mpVC.volume = voice;
- (void)leftSwipGes:(UIPanGestureRecognizer *)leftSwip
{
//滑动方法获取到当前位置的y坐标
leftCurrentY = [leftSwip translationInView:leftView].y;
NSLog(@"left");
//当前坐标大于上一次移动的坐标,为向下滑动
if (leftCurrentY > leftLastY) {
if (light > 0) {
//向下滑动屏幕变暗,亮度下降
light = light - 0.01;
}
else{
//当亮度为0时固定为0,禁止为负值
light = 0;
}
}
else
{
if (light < 1) {
//向上滑动亮度增加
light = light + 0.01;
}
else{
//当亮度为1时固定为1,禁止大于1
light = 1;
}
}
//设置屏幕亮度
[UIScreen mainScreen].brightness = light;
//当前位置的上一次移动的位置y坐标
leftLastY = leftCurrentY;
}
//此处除参数外原理一样,不再额外注释
- (void)rightSwipGes:(UIPanGestureRecognizer *)rightSwip
{
NSLog(@"right");
rightCurrentY = [rightSwip translationInView:rightView].y;
if (rightCurrentY > rightLastY) {
if (voice > 0) {
voice = voice - 0.01;
}
else{
voice = 0;
}
}
else
{
if (voice < 1) {
voice = voice + 0.01;
}
else{
voice = 1;
}
}
//设置系统音量
_mpVC.volume = voice;
rightLastY = rightCurrentY;
}
//从budle路径下读取音频文件,这个文件名是你的歌曲名字,mp3是你的音频格式 NSString *string = [[NSBundle mainBundle] pathForResource:@"夜空中最亮的星" ofType:@"mp3"]; NSString *playUrl = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //转码成UTF-8 否则可能会出现错误 //把音频文件转换成url格式 NSURL *url = [NSURL URLWithString:playUrl]; //初始化音频类 并且添加播放文件 _avAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; //设置初始音量大小 _avAudioPlayer.volume = voice; //设置音乐播放次数 -1为一直循环 _avAudioPlayer.numberOfLoops = -1; //预播放 [_avAudioPlayer prepareToPlay]; [_avAudioPlayer play];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有