kCAMediaTimingFunctionEaseInEaseOut不影响UIImageView

时间:2015-06-02 21:50:42

标签: ios objective-c uiimageview catransition

我有一个循环的图像,我试图使用kCAMediaTimingFunctionEaseInEaseOut从一个淡入淡出到另一个,所以它不是那么突然。我的UIImageView正在从MutableArray接收对象。这是我用来实现淡入淡出效果的代码。

 imageViewContainer = [UIView new];
imageViewContainer.frame = CGRectMake(0, 0, 320, 620);
imageViewContainer.backgroundColor = [UIColor clearColor];
[self.view1 addSubview:imageViewContainer];
for (int i = 0; i < [homescreenPictureArray count]; i++) {
    homescreenPictureView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 50, 320, 620)];
    homescreenPictureView.animationImages = homescreenPictureArray;
    homescreenPictureView.animationDuration = 15;
    [homescreenPictureView setAlpha:1.0f];
    homescreenPictureView.contentMode = UIViewContentModeScaleAspectFill;
    [imageViewContainer.layer addAnimation:pictureDisolve forKey:nil];
    [imageViewContainer addSubview:homescreenPictureView];

    pictureDisolve = [CATransition animation];
    pictureDisolve.duration = 1.0f;
    pictureDisolve.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pictureDisolve.type = kCATransitionFade;
    [homescreenPictureView.layer addAnimation:pictureDisolve forKey:@"imageViewContainer"];
    [homescreenPictureView startAnimating];

编译时我没有收到任何错误,但它没有影响图像。澄清为什么它不起作用将不胜感激。提前谢谢!

3 个答案:

答案 0 :(得分:0)

您使用的过渡类型是错误的。您需要使用kCATransitionFade

答案 1 :(得分:0)

您需要指定key值。例如@"subviews"。 它定义,何时以及将要转变的内容。

pictureDisolve = [CATransition animation];
    pictureDisolve.duration = 1.0f;
    pictureDisolve.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pictureDisolve.type = kCATransition;
    [homescreenPictureView.layer addAnimation:pictureDisolve forKey:@"subviews"];

答案 2 :(得分:0)

所以我现在正在开展一个不同的项目,但我想我会为将来看到这个的人提供一个kCATransitionFade的好例子。

` - (void)fadeIn {

view1.image = background1;
view2.image = background2;

CATransition *fadeIn = [CATransition animation];
fadeIn.duration = 2.0f;
fadeIn.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
fadeIn.type = kCATransitionFade;
fadeIn.delegate = self;
[self.view.layer addAnimation:fadeIn forKey:nil];
view1.hidden = YES;
view2.hidden = NO;

NSLog(@"Image 1");

}

- (void)fadeOut {

view1.image = background1;
view2.image = background2;

CATransition *fadeIn = [CATransition animation];
fadeIn.duration = 2.0f;
fadeIn.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
fadeIn.type = kCATransitionFade;
fadeIn.delegate = self;
[self.view.layer addAnimation:fadeIn forKey:nil];
view1.hidden = NO;
view2.hidden = YES;

NSLog(@"Image 2");

} `

对于我的项目,我把它留作[self fadeIn]或[self fadeOut]使用,但如果你愿意,可以通过调用将它们组合成单个函数

-(void) fadeFunction {

if (self.view == view1) {
    [self fadeIn];
} else {
    [self fadeOut];
}

}