【发布时间】:2014-02-23 00:22:34
【问题描述】:
我是 iOS 编程新手,无法解决我的应用程序中的以下错误:
Xcode 5.0.2 上的故事板用于创建应用程序屏幕。一个简单的选项卡视图控制器是应用程序的主屏幕。每个选项卡栏项都通过导航控制器链接到视图控制器。其中一个视图控制器 (S1) 包含一个按钮,该按钮在录制音频几秒钟后以编程方式触发 segue。 segue 转换到另一个屏幕 (S2),该屏幕有时在标签栏上方包含一个黑条。
编辑
有关该错误的更多详细信息:
可以通过应用程序中的另一个屏幕 (S3) 访问屏幕 S2。但是,通过 S3 打开时,黑条永远不会出现在 S2 上。该栏仅在通过 S1 访问时出现在 S2 上。因此,我认为这与我在 S1 中所做的事情更相关(例如录音或
sleepForTimeInterval,请参见下面的代码)。更改设备方向后黑条消失。
在 S1 或 S2 中未设置布局约束。
在 iPhone 4、4S 和 5 上观察到此错误。未在 5S 上尝试。
这里是S1的实现:
@interface S2ViewController () <AVAudioPlayerDelegate, AVAudioRecorderDelegate>
@property (nonatomic, strong) AVAudioRecorder *audioRecorder;
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
@property (weak, nonatomic) IBOutlet UIButton *btnRecord;
@property Parameters* parameters;
@property BOOL permissionGranted;
@end
@implementation STVIdentifyViewController
- (IBAction) recordAudio:(UIButton *)sender
{
[self startRecordingAudio];
}
- (void) startRecordingAudio
{
NSError* error = nil;
NSURL* audioRecordingURL = [self audioRecordingPath];
self.audioRecorder = [[AVAudioRecorder alloc]
initWithURL:audioRecordingURL
settings:[self audioRecordingSettings]
error:&error];
if (self.audioRecorder != nil)
{
self.audioRecorder.delegate = self;
if ([self.audioRecorder prepareToRecord] && [self.audioRecorder record])
{
[self performSelector:@selector(stopRecordingOnAudioRecorder:)
withObject:self.audioRecorder afterDelay:5.0];
}
}
}
- (void) stopRecordingOnAudioRecorder:(AVAudioRecorder *)paramRecorder
{
[paramRecorder stop];
}
- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
if (flag)
{
[self doSomeProcessingOnTheAudio];
}
self.audioRecorder = nil;
}
- (void) doSomeProcessingOnTheAudio
{
[NSThread sleepForTimeInterval:1.0];
AnotherClass* ACInstance = [[AnotherClass alloc] init];
self.parameters = [ACInstance run];
if (self.parameters)
{
[self performSegueWithIdentifier: @"s1tos2" sender: self];
}
}
- (NSDictionary *) audioRecordingSettings
{
return @{
AVFormatIDKey : @(kAudioFormatLinearPCM),
AVSampleRateKey : @(11025.0f),
AVNumberOfChannelsKey : @1,
};
}
- (NSURL *) audioRecordingPath
{
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSURL *docFolderUrl = [fileManager URLForDirectory:NSDocumentDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:NO
error:nil];
return [docFolderUrl URLByAppendingPathComponent:@"recording"];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"s1tos2"])
{
S2ViewController* s2vc = (S2ViewController*) segue.destinationViewController;
s2vc.parameters = self.parameters;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDuckOthers
error:nil];
[session requestRecordPermission:^(BOOL granted)
{
self.permissionGranted = granted;
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
【问题讨论】:
标签: ios storyboard segue