1

我有以下代码从左到右缩小 UIView 并在动画完成后将其从超级视图中删除:

    UIView* coverView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 300, 50)];
    UIImageView* imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"swipe_rl.png"]];
    [imageView setContentMode:UIViewContentModeScaleToFill];
    [imageView setFrame:coverView.bounds];
    [coverView addSubview:imageView];
    [coverView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
    coverView.clipsToBounds = YES;
    [self.view addSubview:coverView];
    CGRect frame = coverView.frame ;
    [UIView animateWithDuration:5.0 animations:^{
    [coverView setFrame:CGRectMake(frame.origin.x + frame.size.width, frame.origin.y, 0, frame.size.height)];
    } completion:^(BOOL finished){
        [coverView removeFromSuperview];
    }];

但是,图片的左侧部分保留,图片的右侧部分消失,如您在图片中看到的那样。出于特定目的,我希望左侧部分消失而右侧部分保留。我该怎么做?

对于那些想知道我为什么想要这个的人:

- Basically, I want a display-from-left-to-right animation (It means you have a picture and the left of the picture appears first and the the middle and the whole picture appears)
- I do this by adding a second view above the first picture and then shrink the second view from left to right. The first view will then be revealed from left to right.
- Look at http://i1289.photobucket.com/albums/b510/yenmach/right_to_left_zps80b9e9bb.jpg and http://i1289.photobucket.com/albums/b510/yenmach/left_to_right_zps9214dc4a.jpg

从头缩小

在动画中间收缩

4

3 回答 3

3

//尝试这个.......

 CGRect frame = coverView.frame ;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
imageView.frame = CGRectMake(frame.origin.x - 2*frame.size.width,imageView.frame.origin.y, frame.size.width, frame.size.height);
coverView.frame = CGRectMake(frame.origin.x + frame.size.width, frame.origin.y, frame.size.width, frame.size.height);
[UIView commitAnimations];
于 2013-01-24T05:38:50.647 回答
0

尝试更改 UIImageView contentMode属性,

[imageView setContentMode: UIViewContentModeRight];

我有同样的要求,当时这对我来说很好。

于 2013-01-24T04:58:23.203 回答
0

不完全是一个解决方案,而是一种解决方法,如果您要使用具有一致背景(理想情况下为纯色)的它,您可以让另一个视图在图像视图上方设置动画,然后在动画完成后将两者都删除。

于 2013-01-24T04:22:15.557 回答