我的代码:
- (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) 我有我的一些代码AppDelegate
的applicationWillTerminate:
方法,但我不知道如何测试它是否工作.使用Xcode停止模拟器不会触发它.
如何在applicationWillTerminate中测试代码:?
请注意,这是特定于模拟器而不是设备.
当按下某个控制器时,我正在更改导航栏的背景图像.我想为这种变化制作动画.我可以使用以下代码执行此操作:
[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)
但是,这会阻止应用于navigationBarTitle
和UIBarButtonItem
s 的默认推送动画.
如何让背景更改和推动动画一起工作?
我希望尽可能使用vanilla作为解决方案.
PS:我无法使用,tintColor
因为背景是纹理的.
之前已经回答了很多次,但这些答案都没有与iOS 6兼容.提到iOS 6的唯一答案是使用一个名为Jailcoder的工具,这对我来说不起作用.
我尝试过的:
我正在使用Xcode 4.5.1和iOS 6.0.1.请注意,Xcode 4.5.1没有针对6.0.1的SDK,但我认为这不会产生影响.
该文档NSUserDefaults
说明该synchronise
方法是定期调用的,但没有提及频率.10分钟的谷歌搜索没有透露任何信息.
这个synchronise
方法的频率是多少?
当前代码:
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
):
结果:
我找到了这个答案,但它只适用于对称图像.也许我可以修改这个答案供我使用.
这是我的情况:
我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) 我希望在用户的库中获取一个MPMediaItemCollection
或NSArray
所有艺术家.这是我当前的代码(显然不起作用):
- (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) 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 ×8
objective-c ×3
xcode ×2
avfoundation ×1
calayer ×1
ios6 ×1
jailbreak ×1
nsrange ×1
swift ×1
uiimage ×1
uiimageview ×1