Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS中的图像转换器_Ios - Fatal编程技术网

iOS中的图像转换器

iOS中的图像转换器,ios,Ios,我正在尝试让我的应用程序从3个屏幕进行基本的背景更改。这是我的.h文件 #import <UIKit/UIKit.h> @class BIDYellowViewController; @class BIDBlueViewController; @class BIDGreenViewController; @interface BIDSwitchViewController : UIViewController @property (strong, nonatomic) BIDY

我正在尝试让我的应用程序从3个屏幕进行基本的背景更改。这是我的.h文件

#import <UIKit/UIKit.h>

@class BIDYellowViewController;
@class BIDBlueViewController;
@class BIDGreenViewController;

@interface BIDSwitchViewController : UIViewController

@property (strong, nonatomic) BIDYellowViewController *yellowViewController;
@property (strong, nonatomic) BIDBlueViewController *blueViewController;
@property (strong, nonatomic) BIDGreenViewController *greenViewController;

- (IBAction)switchViews:(id)sender;


@end

我遇到的问题是,在第一个循环中,它重复绿色屏幕两次,然后继续正常工作。我是否遗漏了什么,或者我应该使用switch:case语句(如果是,我将如何执行)?

如果要连续重复,则使用全局计数变量作为

static int count=0;
并将代码用作:

- (IBAction)switchViews:(id)sender
{
    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

    switch (count) {
        case 0:

            [greenView removeFromSuperview];
            [blueView removeFromSuperview];

            [self.view addSubview:yellowView];
            break;
        case 1:

            [yellowView removeFromSuperview];
            [greenView removeFromSuperview];

            [self.view addSubview:blueView];

            break;
        case 2:

            [blueView removeFromSuperview];
            [yellowView removeFromSuperview];

            [self.view addSubview:greenView];

            break;

    }

    count++;

    if (count==3) {
        count=0;
    }

    [UIView commitAnimations];
}
您还可以将三个xib与单个ViewController一起使用,只需将xib的类更改为您希望这样使用的ViewController的类---


如果您有viewControllers,那么为什么要使用addSubView?或简单使用UIView不需要使用三个viewControllers您的意思是要重复它?或停止重复它我需要它重复。按下按钮时,它会旋转到“黄色”;再按一次,它会旋转为绿色;再次按下它,它会旋转到蓝色;再按一次,它会变成黄色,……等等……我对iOS/Xcode很陌生,不知道在哪里插入你的建议?我需要将它设置为每种颜色都有一个我已经创建的.h和.m文件。你的一些建议会在那些文件里吗?任何更详细的帮助都将不胜感激。是的,这是我给你的重复代码检查我的回答如果你不知道代码放在哪里,那么请保持代码原样,并使用我在SwitchView方法中使用的计数和切换
- (IBAction)switchViews:(id)sender
{
    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

    switch (count) {
        case 0:

            [greenView removeFromSuperview];
            [blueView removeFromSuperview];

            [self.view addSubview:yellowView];
            break;
        case 1:

            [yellowView removeFromSuperview];
            [greenView removeFromSuperview];

            [self.view addSubview:blueView];

            break;
        case 2:

            [blueView removeFromSuperview];
            [yellowView removeFromSuperview];

            [self.view addSubview:greenView];

            break;

    }

    count++;

    if (count==3) {
        count=0;
    }

    [UIView commitAnimations];
}
BIDViewController *yellowViewController;
BIDViewController *blueViewController;
BIDViewController *greenViewController;


self.yellowViewController = [[BIDViewController alloc]initWithNibName:@"YellowView" bundle:nil];
self.greenViewController = [[BIDViewController alloc] initWithNibName:@"GreenView" bundle:nil];
self.blueViewController = [[BIDViewController alloc] initWithNibName:@"BlueView" bundle:nil];