Posts

Post not yet marked as solved
0 Replies
210 Views
I have 2 questions with Xcode's Instruments. I have filtered 30s in track, but the CPU Time shown below is much more than 30s. It is not standed for the whole track either because it will change when I change the filter above. machkernel uses 57.1% CPU and mediaserverd uses 24.9%, but machkernel's CPU time is thrible more of mediaserverd. Why the proportion of %CPU is not equal to CPU time? !Here is the image - https://discussions.apple.com/content/attachment/4575d4d3-3ccf-4e45-876d-9ffb7ca88499
Posted
by wkx.
Last updated
.
Post not yet marked as solved
1 Replies
711 Views
- (void)viewDidLoad { [super viewDidLoad]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 0, 0)]; label.font = [UIFont boldSystemFontOfSize:30]; label.text = @"Your Name"; [label sizeToFit]; UIImage *gradientImage = [self.class gradientImageWithSize:label.frame.size beginColor:UIColor.redColor endColor:UIColor.yellowColor]; label.textColor = [UIColor colorWithPatternImage:gradientImage]; [self.view addSubview:label];}+ (UIImage *)gradientImageWithSize:(CGSize)size beginColor:(UIColor *)beginColor endColor:(UIColor *)endColor{ CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.colors = @[(__bridge id)beginColor.CGColor, (__bridge id)endColor.CGColor]; gradientLayer.startPoint = CGPointMake(0, 0.5); gradientLayer.endPoint = CGPointMake(1, 0.5); gradientLayer.frame = CGRectMake(0, 0, size.width, size.height); UIGraphicsBeginImageContext(gradientLayer.bounds.size); [gradientLayer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image;}---I want to set gradient color to the text in UILabel but find that if the text is non-english language, the gradient color truncated. Images below will show the case. Is this a bug?https://welkin-xie.oss-cn-shenzhen.aliyuncs.com/1.pnghttps://welkin-xie.oss-cn-shenzhen.aliyuncs.com/2.pnghttps://welkin-xie.oss-cn-shenzhen.aliyuncs.com/3.png---Emmm, non-english can not be post here, I make a html with the text in the images. Just copy them and replace the line oflabel.text = @"Your Name";https://welkin-xie.oss-cn-shenzhen.aliyuncs.com/gradient-1.html
Posted
by wkx.
Last updated
.
Post not yet marked as solved
1 Replies
808 Views
I find that if I stop an on going animation and start another immediately, the new one will not work. Just show my code below.- (void)viewDidLoad { [super viewDidLoad]; [self showTipsAnimation:@"123"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self showTipsAnimation:@"321"]; });}- (void)showTipsAnimation:(NSString *)tips{ if (tips.length == 0) { return; } if (!self.tipsLabel) { self.tipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 0, 0)]; self.tipsLabel.font = [UIFont systemFontOfSize:14]; self.tipsLabel.userInteractionEnabled = NO; self.tipsLabel.textColor = [UIColor redColor]; [self.view addSubview:self.tipsLabel]; } [self.tipsLabel.layer removeAllAnimations]; CGFloat textWidth = [tips sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]}].width; self.tipsLabel.frame = CGRectMake(10, 100, textWidth, [UIFont systemFontOfSize:14].pointSize); self.tipsLabel.text = tips; CAKeyframeAnimation *movementAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; movementAnim.keyTimes = @[@0, @0.25, @0.75, @1]; movementAnim.values = @[[NSValue valueWithCGPoint:CGPointMake(10 + CGRectGetWidth(self.tipsLabel.frame) * 0.5, 100 + CGRectGetHeight(self.tipsLabel.frame) / 2)], [NSValue valueWithCGPoint:CGPointMake(10 + CGRectGetWidth(self.tipsLabel.frame) * 0.5, 90 + CGRectGetHeight(self.tipsLabel.frame) / 2)], [NSValue valueWithCGPoint:CGPointMake(10 + CGRectGetWidth(self.tipsLabel.frame) * 0.5, 90 + CGRectGetHeight(self.tipsLabel.frame) / 2)], [NSValue valueWithCGPoint:CGPointMake(10 + CGRectGetWidth(self.tipsLabel.frame) * 0.5, 90 + CGRectGetHeight(self.tipsLabel.frame) / 2)]]; movementAnim.duration = 2; movementAnim.delegate = self; [self.tipsLabel.layer addAnimation:movementAnim forKey:nil];}Run it, and will see the first animation will be stopped, but the second will not begin. But I also find that if I change the last line of the code to:[self.tipsLabel.layer addAnimation:movementAnim forKey:@"1"];then everything will be fine. So why? Is this a bug?
Posted
by wkx.
Last updated
.