質問

これについてのチュートリアルや質問の負荷を覗いてきましたが、私が探しているものを見つけることができないようです、そして私は単純なステップを見逃している気持ちを持っています。ロープはこのように私と一緒にくる。

Xcode 4.3.3に画像ランダマイザを作成しています。ウィンドウ全体はUIImageViewオブジェクトでカバーされているので、スワイプで画像をランダウンするアプリが必要なので、UIImageViewをスワイプできます。これが私が持っているものです:

.hファイル:

@interface ViewController : UIViewController <UIGestureRecognizerDelegate> {
IBOutlet UIImageView *quotePage;

}

-(IBAction)random;
-(void)screenWasSwiped;

@end
.

と私の.mファイル:

@interface ViewController ()

@end

@implementation ViewController

-(IBAction)random {
int image = rand() % 4;
switch (image) {
    case 0:
        quotePage.image = [UIImage imageNamed:@"Quote1.png"];
        break;
    case 1:
        quotePage.image = [UIImage imageNamed:@"Quote2.png"];
        break;
    case 2:
        quotePage.image = [UIImage imageNamed:@"Quote3.png"];
        break;
    case 3:
        quotePage.image = [UIImage imageNamed:@"Quote4.png"];
        break;
    default:
        break;
}
}


-(void)viewDidLoad {
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]         initWithTarget:self action:@selector(screenWasSwiped)];
swipeLeft.numberOfTouchesRequired = 1;
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
quotePage.userInteractionEnabled = YES;

}

@end
.

私はストーリーボードのスワイプジェスチャーに「ランダム」アクションを接続することが可能であると思いましたが、うまくいきませんでした。スレッド1のメッセージは次のとおりです。

2012-07-27 15:04:32.012 QuoteRandom [1057:C07] - [ViewController ScreenWassWiped]:インスタンス0x6868210

に送信された認識されていないセレクタ

だから私は「ScreenWasswiped」をイメージラスタマイザに接続し、スワイプジェスチャーをUIImageViewに適用しなければならないと思いますが、それを理解するのに苦労しています。私はどんな指導も感謝します!事前にありがとう!

役に立ちましたか?

解決

-(IBAction)randomUISwipeGestureRecognizerメソッドを変更するには、initメソッドを次のように呼び出すことができます。

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(random)];
.

このように、あなたがスワイプするたびに新しいランダムな画像を得るでしょう。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top