如何使用某些转换

时间:2015-08-18 13:35:46

标签: ios objective-c uiimageview uiimage

我正在制作图像编辑器应用程序。

我可以更改UIImage的{​​{1}},但我希望它更高效,更漂亮。

目前我正在将UIImageView更改为

UIImage

它会直接更改if(image) { userImageView.image = image; } 。如何制作UIImage效果?

3 个答案:

答案 0 :(得分:1)

 UIImage *image = [UIImage imageWithData:imageData];
 [UIView transitionWithView:YourUIImageView
                              duration:2.0f
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                YourUIImageView.image = image;
                            } completion:nil]; 

在问这个问题之前先做一些谷歌搜索并回答。

1

答案 1 :(得分:1)

试试这个......

 - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    self.fadeDuration=1;
}
return self;
}
-(void)setImage:(UIImage *)newImage{

if(!self.image||self.fadeDuration<=0){
    super.image=newImage;
} else {
    UIImageView *iv=[[UIImageView alloc] initWithFrame:self.bounds];
    iv.contentMode=self.contentMode;
    iv.image=super.image;
    iv.alpha=1;
    [self addSubview:iv];
    super.image=newImage;
    [UIView animateWithDuration:self.fadeDuration delay:0       options:UIViewAnimationCurveEaseInOut animations:^{
        iv.alpha=0;
    } completion:^(BOOL finished) {
        [iv removeFromSuperview];
    }];
     }
    }

答案 2 :(得分:0)

尝试这样的事情:

-(void)fade{

    //fade out
    [UIView animateWithDuration:1.0f animations:^{

        [userImageView setAlpha:0.0f];

    } completion:^(BOOL finished) {

        //fade in
        [UIView animateWithDuration:1.0f animations:^{
            userImageView.image = image;
            [userImageView setAlpha:1.0f];

        } completion:nil];

    }];
}