我是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.
}
答案 0 :(得分:0)
应该是自动布局问题。检查视图的底部约束条形图。