小编som*_*dev的帖子

iOS Photos Framework:是否可以从"People"智能文件夹中访问照片?

我正在尝试访问PHAssetCollections PHCollectionList.主要思想是从我的iPhone(iOS 10.2)上的"People"智能文件夹中获取所有集合(以及内部资产).要获取PHCollectionList我正在使用当前代码:

PHFetchResult *listFetchResult = 
[PHCollectionList fetchCollectionListsWithType:PHCollectionListTypeSmartFolder 
                                       subtype:PHCollectionListSubtypeSmartFolderFaces
                                       options:nil];
PHCollectionList *list = listFetchResult[0];
NSLog(@"title: %@",list.localizedTitle);
Run Code Online (Sandbox Code Playgroud)

这按预期工作.控制台输出:"标题:人物".list.canContainAssets返回NOlist.canContainCollections返回YES.
然后,我正在尝试从list以下位置获取资产集合:

PHFetchResult *collectionFetchResult = 
[PHCollection fetchCollectionsInCollectionList:list options:nil];
Run Code Online (Sandbox Code Playgroud)

collectionFetchResult.count 总是返回0.但如果我打开照片应用程序,我会在"人物"文件夹中看到10个集合.

是否可以从照片应用中的"人物"智能相册访问集合(及其中的照片)?

iphone objective-c ios photosframework

9
推荐指数
1
解决办法
960
查看次数

将一个AAC文件附加到另一个AAC文件时输出音频设置

我的应用程序使用带有音频参数的AVAudioRecorder逐个记录两个音频文件:

        NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
                                    [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
                                    [NSNumber numberWithInt:1], AVNumberOfChannelsKey,
                                    [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
                                    [NSNumber numberWithInt:16],AVEncoderBitDepthHintKey,
                                    [NSNumber numberWithInt:128000], AVEncoderBitRateKey,
                                    nil];
Run Code Online (Sandbox Code Playgroud)

我需要在file1的末尾添加file2.我正在使用那里的解决方案(通过在添加两个文件并使用exportAsynchronouslyWithCompletionHandler:AVAssetExportSession方法导出合成后创建AVMutableCompositionTrack来附加两个音频文件).
它有效,但我有两个输入文件128kbs 44.1kHz 16bit单声道,输出文件格式为:219.4kbs 44.1kHz 16bit立体声.

有没有办法为AVAssetExportSession配置输出音频文件参数?

iphone audio aac objective-c avassetexportsession

6
推荐指数
1
解决办法
546
查看次数

Swift协议继承

我有快速的代码:

protocol ParentProtocol {
    // stuff
}

protocol ChildProtocol: ParentProtocol {
    // additional stuff
}

protocol FooProtocol {
    var variable: ParentProtocol? { get }
}

class Foo:FooProtocol {
    var variable: ChildProtocol?
}
Run Code Online (Sandbox Code Playgroud)

我有编译器错误:

类型'Foo'不符合协议'FooProtocol'

我知道,根据FooProtocol,变量类型必须是ParentProtocol类型.另一方面ChildProtocol继承自ParentProtocol,所以它也是一个ParentProtocol

是否有任何解决方案以这种方式使用协议继承?

swift swift-protocols

6
推荐指数
1
解决办法
4104
查看次数

具有自动布局的UILabel高度动画

我的观点和UIButton都有一个UILabel.当按钮触摸UILabel时应更改动画高度,取决于标签内容.我在尝试这个:

    - (void)viewDidLoad {
        self.textLabel= [[UILabel alloc] initWithFrame:CGRectZero];
        self.textLabel.numberOfLines=0;
        self.textLabel.font= [UIFont systemFontOfSize:14];
        self.textLabel.backgroundColor= [UIColor lightGrayColor];
        self.textLabel.text= @"short text";
        [self.view addSubview:self.textLabel];
        [self.textLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
        [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_textLabel]-10-|"
        options:0
        metrics:nil
        views:NSDictionaryOfVariableBindings(_textLabel)]];


        self.button= [UIButton buttonWithType:UIButtonTypeSystem];
        [self.button addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
        [self.button setTitle:@"Tap" forState:UIControlStateNormal];
        self.button.backgroundColor= [UIColor greenColor];
        [self.button setTranslatesAutoresizingMaskIntoConstraints:NO];
        [self.view addSubview:self.button];

        [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_button]-10-|"
                                   options:0
                                   metrics:nil
                                   views:NSDictionaryOfVariableBindings(_button)]];

        [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[_textLabel(>=0)]-10-[_button(==20)]"
                                   options:0
                                   metrics:nil
                                    views:NSDictionaryOfVariableBindings(_textLabel,_button)]];

}

- (void)buttonTouched:(id)buttonTouched {
        self.shortText =!self.shortText;
        self.textLabel.text= self.shortText ?@"short text":@"long long long text\nlong long long text\nlong long long text\n";
        [UIView animateWithDuration:1.0
                         animations:^{
                             [self.view …
Run Code Online (Sandbox Code Playgroud)

uilabel ios autolayout

5
推荐指数
2
解决办法
2084
查看次数