【问题标题】:How to flip an imageview in the UIAlertView in objective c如何在目标 c 的 UIAlertView 中翻转图像视图
【发布时间】:2013-01-07 22:22:08
【问题描述】:

我有一个 AlertView 和一个 imageView,我必须在翻转动画 (UIViewAnimationTransitionFlipFromLeft/Right) 中显示图像作为警报视图的 subview

我正在使用以下方法

- (void) setAnimationFlip:(UIAlertView*)alertView {

    UIView *containerView = [[UIView alloc]initWithFrame:CGRectMake(20, 40, 150, 150)];
    UIImageView *mainView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"scene1.jpg"]];
    UIImageView *flipToView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"scene2.jpg"]];

    mainView.frame = CGRectMake(20, 40, 200, 210);
    flipToView.frame = CGRectMake(20, 40, 200, 210);

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2.0];

    [UIView setAnimationTransition:([mainView superview] ?
                                    UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
                           forView:containerView cache:YES];
    if ([flipToView superview])
    {
        [flipToView removeFromSuperview];
        [containerView addSubview:mainView];

    }
    else
    {
        [mainView removeFromSuperview];
        [containerView addSubview:flipToView];
    }

    [self.alrtViewPreview addSubview:containerView];
    [self.alrtViewPreview show];

    [UIView commitAnimations];

    //[containerView release];
    //[mainView release];
    //[flipToView release];

}

然后打电话...

    switch (iEffect) {
            case 1:

                [self setAnimationFlip:alrtViewPreview];
                break;
    }

但它对我不起作用,有人可以帮助我吗?

【问题讨论】:

    标签: iphone objective-c xcode uiimageview uialertview


    【解决方案1】:
    -(IBAction)btnClick:(UIButton*)sender {
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:sender cache:YES]; 
        [UIView setAnimationDelegate:self]; 
        [sender setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",self.tileImage]] forState:UIControlStateNormal];
            [sender setTitle:self.tileText forState:UIControlStateNormal];
    
        [UIView commitAnimations];
    
    }
    

    【讨论】:

    • 使用动画块优于“旧”动画代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多