iOS 에서 화면 밝기 와 시스템 볼 륨 을 제어 합 니 다.
3501 단어 ios미끄러지다스크린avaudioplayer
1.화면 밝기 변경
//
light = [UIScreen mainScreen].brightness;
light = 0.5f;
// set
[UIScreen mainScreen].brightness = light;
2.시스템 볼 륨 변경많이 사용 되 는 것 은 MPMusicPlayerController 를 통 해 시스템 볼 륨 을 바 꾸 는 것 으로 주로 MPMusicPlayerController 의 볼 륨 과 시스템 의 동기 화 덕분이다.
MPMusicPlayerController *mpVC = [MPMusicPlayerController applicationMusicPlayer];
//
voice = _mpVC.volume;
voice = 0.5f;
//
_mpVC.volume = voice;
3.미끄럼 응답 방법
- (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;
}
4.AVAudioPlayer 단순 활용
// 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];
마지막 으로 데모 첨부:다운로드 클릭위 에서 설명 한 것 은 편집장 이 소개 한 iOS 에서 화면 밝기 와 시스템 볼 륨(AVAudio Player 기본 용법 과 Masonry 를 추가 하여 간단하게 사용)을 미 끄 러 뜨리 는 것 입 니 다.여러분 께 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.편집장 은 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swift의 패스트 패스Objective-C를 대체하기 위해 만들어졌지만 Xcode는 Objective-C 런타임 라이브러리를 사용하기 때문에 Swift와 함께 C, C++ 및 Objective-C를 컴파일할 수 있습니다. Xcode는 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.