小编duc*_*i9y的帖子

iOS AVFoundation:如何从mp3文件中获取图稿?

我的代码:

- (void)metadata {
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:self.fileURL options:nil];

NSArray *artworks = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata withKey:AVMetadataCommonKeyArtwork keySpace:AVMetadataKeySpaceCommon];
NSArray *titles = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata withKey:AVMetadataCommonKeyTitle keySpace:AVMetadataKeySpaceCommon];
NSArray *artists = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata withKey:AVMetadataCommonKeyArtist keySpace:AVMetadataKeySpaceCommon];
NSArray *albumNames = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata withKey:AVMetadataCommonKeyAlbumName keySpace:AVMetadataKeySpaceCommon];

AVMetadataItem *artwork = [artworks objectAtIndex:0];
AVMetadataItem *title = [titles objectAtIndex:0];
AVMetadataItem *artist = [artists objectAtIndex:0];
AVMetadataItem *albumName = [albumNames objectAtIndex:0];

if ([artwork.keySpace isEqualToString:AVMetadataKeySpaceID3]) {
    NSDictionary *dictionary = [artwork.value copyWithZone:nil];
    self.currentSongArtwork = [UIImage imageWithData:[dictionary objectForKey:@"data"]];
}
else if ([artwork.keySpace isEqualToString:AVMetadataKeySpaceiTunes]) {
    self.currentSongArtwork = …
Run Code Online (Sandbox Code Playgroud)

objective-c avfoundation ios

16
推荐指数
2
解决办法
1万
查看次数

为什么不在iOS模拟器中停止应用程序触发applicationWillTerminate:?

我有我的一些代码AppDelegateapplicationWillTerminate:方法,但我不知道如何测试它是否工作.使用Xcode停止模拟器不会触发它.

如何在applicationWillTerminate中测试代码:?

请注意,这是特定于模拟器而不是设备.

xcode objective-c ios-simulator

14
推荐指数
1
解决办法
4482
查看次数

我如何动画UINavigationBar setBackgroundImage:forBarMetrics:?

当按下某个控制器时,我正在更改导航栏的背景图像.我想为这种变化制作动画.我可以使用以下代码执行此操作:

[UIView transitionWithView:self.navigationController.navigationBar
                  duration:0.3f
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"now-playing-nav-bar.png"]
                                                 forBarMetrics:UIBarMetricsDefault];
} completion:NULL];
Run Code Online (Sandbox Code Playgroud)

但是,这会阻止应用于navigationBarTitleUIBarButtonItems 的默认推送动画.

如何让背景更改和推动动画一起工作?

我希望尽可能使用vanilla作为解决方案.

PS:我无法使用,tintColor因为背景是纹理的.

objective-c uinavigationcontroller ios ios6

9
推荐指数
2
解决办法
3983
查看次数

如何在没有Apple Developer许可证的情况下在iPhone上测试应用程序?

之前已经回答了很多次,但这些答案都没有与iOS 6兼容.提到iOS 6的唯一答案是使用一个名为Jailcoder的工具,这对我来说不起作用.

我尝试过的:

  • 创建一个假的代码签名证书
  • 修改SDKSettings.plist
  • 使用Jailcoder来修补Xcode以及我的项目

我正在使用Xcode 4.5.1和iOS 6.0.1.请注意,Xcode 4.5.1没有针对6.0.1的SDK,但我认为这不会产生影响.

xcode jailbreak ios

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

NSUserDefaults多久会同步一次?

该文档NSUserDefaults说明该synchronise方法是定期调用的,但没有提及频率.10分钟的谷歌搜索没有透露任何信息.

这个synchronise方法的频率是多少?

nsuserdefaults ios

5
推荐指数
1
解决办法
576
查看次数

使用可调整大小的UIImage掩码屏蔽任意大小的UIImageView

当前代码:

    self.backgroundImageView.image = [self.message imageOfSize:self.message.size]; // Random image, random size

    UIImage *rightBubbleBackground = [[UIImage imageNamed:@"BubbleRight"]
    resizableImageWithCapInsets:BubbleRightCapInsets
    resizingMode:UIImageResizingModeStretch];

    CALayer *mask = [CALayer layer];
    mask.contents = (id)[rightBubbleBackground CGImage];

    mask.frame = self.backgroundImageView.layer.frame;
    self.backgroundImageView.layer.mask = mask;
    self.backgroundImageView.layer.masksToBounds = YES;
Run Code Online (Sandbox Code Playgroud)

这不能正常工作.尽管应用了蒙版,但即使它设置了大小调整大小的内容(),rightBubbleBackground也不会正确调整大小以适应self.backgroundImageView大小BubbleRightCapInsets.

原始图片:

原始图像

蒙版图片(rightBubbleBackground):

面具

结果:

结果

我找到了这个答案,但它只适用于对称图像.也许我可以修改这个答案供我使用.

calayer uiimageview uiimage ios

5
推荐指数
1
解决办法
1934
查看次数

逐个字符地向NSMutableAttributedString添加属性

这是我的情况:

NSMutableAttributedString在文本视图中没有属性.每当用户按下退格键时,我都不希望删除一个字符,我希望它能够被删除,就像生产力套件的"Track Changes"功能一样.我希望用户能够在此之后继续正常输入.这是我开始的方式:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if (text.length == 0 && textView.text.length == 0) return YES;

if (text.length == 0 && !([[textView.text substringFromIndex:textView.text.length - 1] isEqualToString:@" "] || [[textView.text substringFromIndex:textView.text.length - 1] isEqualToString:@"\n"])) {

    textView.attributedText = [self strikeText:textView.attributedText];

    textView.selectedRange = NSMakeRange(textView.attributedText.length - 1, 0);

    return NO;
}
return YES;
}

- (NSAttributedString *)strikeText:(NSAttributedString *)text
{
NSRange range;
NSMutableAttributedString *returnValue = [[NSMutableAttributedString alloc] initWithAttributedString:text];

if (![text attribute:NSStrikethroughStyleAttributeName atIndex:text.length - 1 effectiveRange:&range]) {
    NSLog(@"%@", NSStringFromRange(range));
    NSLog(@"%@", …
Run Code Online (Sandbox Code Playgroud)

nsattributedstring ios nsrange

3
推荐指数
2
解决办法
2万
查看次数

从iOS媒体库中获取所有艺术家的列表

我希望在用户的库中获取一个MPMediaItemCollectionNSArray所有艺术家.这是我当前的代码(显然不起作用):

- (void)viewDidLoad
{
    [super viewDidLoad];
    MPMediaQuery *artistsQuery = [MPMediaQuery artistsQuery];
    self.artistsArray = artistsQuery.collections;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.artistsArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ArtistsCell"];
    cell.textLabel.text = [(MPMediaItemCollection *)self.artistsArray[indexPath.row]   valueForProperty:MPMediaPlaylistPropertyName];
    NSLog(@"%@", cell.textLabel.text);
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

mpmediaitemcollection mpmusicplayercontroller ios

2
推荐指数
1
解决办法
945
查看次数

输入'[NSObject:AnyObject]!' 不符合协议'DictionaryLiteralConvertible'

self.textView.linkTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor(),
                                    NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle]
Run Code Online (Sandbox Code Playgroud)

这给出了编译错误Type '[NSObject : AnyObject]!' does not conform to protocol 'DictionaryLiteralConvertible'.我刚开始使用Swift并且无法弄清楚出了什么问题.

ios swift

2
推荐指数
1
解决办法
2200
查看次数