标签: switch-statement

动画结束后执行操作

我在图像上执行动画,我将其旋转180度.

然后我插入了一个代码来切换到另一个视图.

但是,应用程序在动画结束前切换视图.

我怎样才能等待动画完成以便之后切换视图?

这是我的代码:

- (IBAction)buttonPressed:(id)sender
{
    CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

    imageRotation.fromValue = [NSNumber numberWithFloat:0];
    imageRotation.toValue = [NSNumber numberWithFloat:((180*M_PI)/ 180)];

    imageRotation.duration = 1.5;
    imageRotation.repeatCount = 1;

    imageRotation.removedOnCompletion = NO;
    imageRotation.autoreverses=NO;
    imageRotation.fillMode = kCAFillModeForwards;

    [_image.layer addAnimation:imageRotation forKey:@"imageRotation"];

    // Switching Views
    [self performSegueWithIdentifier: @"ToGalleryVCSegue" sender: self];

}
Run Code Online (Sandbox Code Playgroud)

animation switch-statement wait ios

2
推荐指数
1
解决办法
811
查看次数

我的代码中的switch语句出错.(C++)

我在这个棒球计算器中的switch语句出错了.错误说:"控制转移绕过初始化:"

switch语句用于您希望在此程序中执行的计算类型,例如:

在基本百分比击球平均值等...

// Baseball Stat.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>

using namespace std;
char menu_choice;
// Batting average formula.

float b_average(float hits, float bats) {return hits/bats;};

// On base percentage formula

float OBP(float hits, float walks, float Hit_by_Pitch, float bats, float sac_flys) {return (hits+walks+Hit_by_Pitch) / (bats+walks+Hit_by_Pitch+sac_flys);};

// Strikeout Ratio Formula 

float Strikeout_ratio(float strikeouts, float bats) {return strikeouts/bats;};

// Fielding Average Formula 

float fielding_average(float putouts, float assists, …
Run Code Online (Sandbox Code Playgroud)

c++ switch-statement

2
推荐指数
1
解决办法
292
查看次数

Switch - case表达式必须是常量表达式,我不能生成if-else语句

这是一个QR码生成的项目,这是代码 的来源 这里的源是一个常数的错误我知道它必须放入If-else但我不知道在这个项目中如何有人可以帮助我 ?!

//That is a QR code generator project`enter code here`
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
          case R.id.button1://<--- is the error .. I can't make it If-else statement
           EditText qrInput = (EditText) findViewById(R.id.QR);
           String qrInputText = qrInput.getText().toString();
           Log.v(LOG_TAG, qrInputText);

           //Find screen size
           WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
           Display display = manager.getDefaultDisplay();
           Point point = new Point();
           display.getSize(point);
           int width = point.x;
           int height = point.y;
           int smallerDimension …
Run Code Online (Sandbox Code Playgroud)

android qr-code switch-statement

2
推荐指数
1
解决办法
5820
查看次数

更有效的方法来编码c ++中的else语句

我用C++编写了Nintendo DS编码,但这应该适用于所有c ++.

我已经知道了switch语句,但是我需要创建一组if,then和else,它们有多个参数:

void doSomething(int number)
{
...
}

bool left = true;
bool right = false;
bool top = false;
bool bottom = false;

if (left && top && right)
    doSomething(1);
else if (top && right && bottom)
    doSomething(2);
else if (left && right && bottom)
    doSomething(3);
else if (left && top && bottom)
    doSomething(4);
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

c++ if-statement switch-statement

2
推荐指数
1
解决办法
1253
查看次数

还有其他许多陈述吗?

我正在读取一个csv文件,其中第一行的列名称和行> 1的值.我需要获取列名的位置.我能想到的唯一方法是切换或ifs.我在某个地方读到它,在我的情况下,做ifs更快(更好).但是该文件有很多列(~120).只是想知道是否有替代方案.

private static void Get_Position(string line, performance p)
{
    string[] line_split = line.Split(',');
    for (int i = 0; i < line_split.Length; i++)
    {
       if (line_split[i].Contains(@"(0)\% Processor Time"))
        {
            p.percore[0] = i;
        }
        else if (line_split[i].Contains(@"(1)\% Processor Time"))
        {
            p.percore[1] = i;
        }
        else if (line_split[i].Contains("Private Bytes"))
        {}
        else if (line_split[i].contains("DPC")
        {
         }

        //on and on and on with else ifs
Run Code Online (Sandbox Code Playgroud)

c# if-statement switch-statement

2
推荐指数
1
解决办法
139
查看次数

切换局部变量编译错误

为什么这是编译错误?Java无法同时达到这两种声明bar.

import java.util.Random;

public class SwitchTest {
  public static void main(String[] args) {
    Random r = new Random();
    int foo = r.nextInt(2);

    switch(foo) {
    case 0:
      int bar = r.nextInt(10);
      System.out.println(bar);
      break;
    case 1:
      int bar = r.nextInt(10) + 10; // Doesn't compile!!
      System.out.println(bar);
      break;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

java declaration switch-statement

2
推荐指数
1
解决办法
56
查看次数

使用相同的开关盒但定义不同

我必须在不同的功能中重复使用相同的开关盒.在不同的功能中,开关盒的定义会有所不同.例如:

    int groupID = somenumber;
    private void FunctionA()
    {
        switch (groupID)
        {
            case 0:
                // Do Action A
                break;
            case 1:
                // Do Action B
                break;
            case 2:
                // Do Action C
                break;
        }
    }

    private void FunctionB()
    {
        switch (groupID)
        {
            case 0:
                // Do Action Z
                break;
            case 1:
                // Do Action X
                break;
            case 2:
                // Do Action Y
                break;
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是一次使用相同开关盒的任何方法但定义可能不同吗?

c# switch-statement

2
推荐指数
2
解决办法
145
查看次数

C#切换类的类型

我有以下方法,它将一种类作为参数:

public void test(Type proType){

}
Run Code Online (Sandbox Code Playgroud)

我目前有一个大的if else看起来像:

if(proType == typeof(Class)){}
Run Code Online (Sandbox Code Playgroud)

因为大约有十个看起来不整洁.

我尝试将其转换为开关但无法使其工作.

有没有更好的做法可以让这个或那个让switch语句工作?

           switch (proType)
            {
                case typeof(ClassName):
                    break;
            }
Run Code Online (Sandbox Code Playgroud)

"需要恒定值"

该函数被称为 test(typeof(class))

所以目标是我有一个包含许多小类的Big对象.

typeof(class)switch/if语句允许我决定进入哪个容器来获取对象.

c# if-statement typeof switch-statement

2
推荐指数
1
解决办法
842
查看次数

C++开关语句结束菜单

嘿,我正在为我的C++编程类开发一个Switch选择菜单.我设法让我的菜单工作,但我不知道如何在我所做的菜单中的退出选择上停止程序.

我的代码是

#include <iostream>
using namespace std;

int main()
{
    char selection;

    do
    {
        cout << "  IHCC Computer Science Registration Menu\n";
        cout << "  ====================================\n";
        cout << "  1.  Welcome to Computer Programming In C++\n";
        cout << "  2.  Welcome to Java Programming\n";
        cout << "  3.  Welcome to Android Programming\n";
        cout << "  4.  Welcome to iOS Programming\n";
        cout << "\n";
        cout << "  5.  Exit\n";
        cout << "  ====================================\n";
        cout << "  Enter your selection: ";
        cin …
Run Code Online (Sandbox Code Playgroud)

c++ switch-statement

2
推荐指数
1
解决办法
3万
查看次数

在Case语句中使用带有多个选项的变量

是否有可能做类似以下的事情(以及如何?)(,或者为什么不呢?):

MATCH="--opt1 | --opt2"
while true ; do
    case $1 in
        $MATCH)
             echo "option $2" found;
             shift 2;;
        *)
             unknown option; exit 1;
    esac
done
Run Code Online (Sandbox Code Playgroud)

因为我不明白这不起作用.但是,只有像MATCH =" - opt1"这样的替代方案就可以了.

编辑1:可能的解决方案

可以简单地检查给定选项是否出现在多个允许选项的字符串中,而不是使用case语句,例如通过使用grep和if.要动态地完成它,可以考虑以下解决方案,它也可能与case语句结合或嵌入:

while true ; do
if [ -n "$(echo $MATCHES|grep -- $1)" ]; then
    echo "found option $1 with value $2"
    shift 2
fi
done
Run Code Online (Sandbox Code Playgroud)

variables bash switch-statement

2
推荐指数
1
解决办法
3065
查看次数