我试图使用setBeginTime将图层的不透明度和位置的动画延迟3秒.我已经调用了图层boxLayer.然而,动画在前3秒(该图层不应显示)中运行良好,图层将显示在其最终位置和不透明度.它不应该.组动画无法解决问题.有人可以帮忙吗?见下面的代码:
// Create an animation that will change the opacity of a layer
CABasicAnimation *fader = [CABasicAnimation animationWithKeyPath:@"opacity"];
// It will last 1 second and will be delayed by 3 seconds
[fader setDuration:1.0];
[fader setBeginTime:CACurrentMediaTime()+3.0];
// The layer's opacity will start at 0.0 (completely transparent)
[fader setFromValue:[NSNumber numberWithFloat:startOpacity]];
// And the layer will end at 1.0 (completely opaque)
[fader setToValue:[NSNumber numberWithFloat:endOpacity]];
// Add it to the layer
[boxLayer addAnimation:fader forKey:@"BigFade"];
// Maintain opacity to 1.0 JUST TO MAKE SURE IT …Run Code Online (Sandbox Code Playgroud) 我试图修改图层中文本的字体属性,但它不会发生.任何人都可以帮忙吗?请在下面找到代码:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// All HypnosisViews start with a clear background color
[self setBackgroundColor:[UIColor clearColor]];
[self setCircleColor:[UIColor lightGrayColor]];
// Create the new layer object
boxLayer = [[CATextLayer alloc] init];
// Give it a size
[boxLayer setBounds:CGRectMake(0.0, 0.0, 300.0, 85.0)];
// Give it a location
[boxLayer setPosition:CGPointMake(160.0, 350.0)];
// Make half-transparent red the background color for the layer
UIColor *reddish = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.75];
// Get CGColor object with the same …Run Code Online (Sandbox Code Playgroud) 视频播放完毕后,我正在显示文本.我正在使用通知技术来实现这一目标.唯一的问题是Observer每隔一段时间被调用两次.它触发"itemDidFinishPlaying"两次(因此同名的方法).我无法预测何时.我不知道为什么.它看起来是随机的(我知道这听起来很奇怪)就好像它工作得很好让我们说连续15次,然后下一次这种行为突然发生了.我做了一个重建并运行应用程序,这次它连续运行19次,然后两次调用Observer等等......不可预测.我已经尝试过每个场景来预测bug以便修复它.到目前为止,这是不可能的.所以我有2个问题.
1)为什么会发生并"随机"?
2)如何解决这个双重调用问题?
这两个以下的对话也没有帮助:
为什么NSNotification中的Observer调用了两次....?
如何阻止NSNotification中的Observer调用两次?
请在下面找到我的代码:
- (void) playAnimation: (NSString *) theString {
UIView *thisCurrentView = self.currentView;
UIView *thisReplacementView = [[UIView alloc] init];
//[avPlayer pause];
[self replaceView: thisCurrentView withView: thisReplacementView];
NSString *filepath = [[NSBundle mainBundle] pathForResource:theString ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
// First create an AVPlayerItem
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:fileURL];
// Subscribe to the AVPlayerItem's DidPlayToEndTime notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
// Pass the AVPlayerItem to a new player
controlledPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
AVPlayerLayer …Run Code Online (Sandbox Code Playgroud) 我正在使用[UIView animateWithDuration ...]来显示我的应用程序的每个页面的文本.每个页面都有自己的文本.我正在刷卡以在页面之间导航.我正在使用1秒的溶解效果,在显示页面后让文本淡入.
问题在于:如果我在1秒内(在此期间文本渐渐消失)中滑动,则当下一页出现并且2个文本将重叠(前一个和当前)时,动画将完成.
我想要实现的解决方案是,如果我碰巧在它发生时滑动,就会中断动画.我无法实现它.[self.view.layer removeAllAnimations]; 不适合我.
这是我的动画代码:
- (void) replaceContent: (UITextView *) theCurrentContent withContent: (UITextView *) theReplacementContent {
theReplacementContent.alpha = 0.0;
[self.view addSubview: theReplacementContent];
theReplacementContent.alpha = 0.0;
[UITextView animateWithDuration: 1.0
delay: 0.0
options: UIViewAnimationOptionTransitionCrossDissolve
animations: ^{
theCurrentContent.alpha = 0.0;
theReplacementContent.alpha = 1.0;
}
completion: ^(BOOL finished){
[theCurrentContent removeFromSuperview];
self.currentContent = theReplacementContent;
[self.view bringSubviewToFront:theReplacementContent];
}];
}
Run Code Online (Sandbox Code Playgroud)
你们知道如何使这项工作?你知道其他任何解决这个问题的方法吗?
ios ×4
layer ×2
animation ×1
avplayer ×1
fonts ×1
objective-c ×1
text ×1
uitextview ×1
uiview ×1