【问题标题】:kCATransitionPush applied to slide in/out image from UIImageview without fade/transparent effects iOSkCATransitionPush 应用于从 UIImageview 滑入/滑出图像,没有淡入淡出/透明效果 iOS
【发布时间】:2015-06-11 17:39:04
【问题描述】:

我在屏幕上的某个位置有一个 UIImageView:

self.imageView = [[UIImageView alloc] init];
self.imageView.clipsToBounds = YES;
self.imageView.image = [UIImage imageNamed:@"food"];
[self.imageView setFrame:CGRectMake(0, 0 , (self.view.frame.size.width/5), 60)];

然后我必须在 UIImageView 中滑入另一个图像,我使用以下代码进行了操作:

self.imageView.image = NULL;
CATransition *animation = [CATransition animation];
        [animation setDuration:0.75];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromLeft];
        animation.delegate = self;
        [[self.imageView layer] addAnimation:animation forKey:nil];

但是当第一张图片滑出时,它会淡出(或者在 imageView 的边缘看起来是透明的)。我尝试了尽可能多的在线解决方案,例如在动画期间设置图层属性以移除淡入淡出或将图层不透明度指定为 1.0,但它们似乎都不起作用。任何帮助,将不胜感激。谢谢!

【问题讨论】:

    标签: ios objective-c xcode uiimageview


    【解决方案1】:

    您可以使用另一个图像视图和UIView 动画尝试不同的方法:

    UIImage *newImage = [UIImage imageNamed:@"newImage"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:newImage];
    imageView.frame = self.imageView.frame;
    [self.view addSubview:imageView];
    
    imageView.transform = CGAffineTransformMakeTranslation(-imageView.frame.size.width, 0);
    [UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveLinear animations:^()
    {
        imageView.transform = CGAffineTransformIdentity;
    }
                     completion:^(BOOL finished)
    {
        self.imageView.image = newImage;
        [imageView removeFromSuperview];
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      • 2012-04-15
      • 2019-11-17
      相关资源
      最近更新 更多