簡単シェイク動作で背景画像の変更☆

ScrollViewの上にH640の画像を縦に並べて、現在表示されている画像毎にシェイク数をカウント。
5回までのカウント数によって画像を変更

実装部分

//シェイク動作
int maii = 0;
int w = 0;
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
	if (event.type == UIEventTypeMotion && motion == UIEventSubtypeMotionShake) {
		count_mo++;
		
		CGPoint ap = self.scrollView.contentOffset;
		gazonh = 640;
		w = ap.y/640;

		if (w != maii) {
			count_mo = 1;
			NSLog(@"me?");
		}
		
		maii = w;

		if (count_mo > 0 && count_mo <= 5) {
			NSString *ll = [NSString stringWithFormat:@"%d",count_mo];
			NSString *path= [[NSBundle mainBundle] pathForResource:ll ofType:@"png"];
			UIImage *imag= [[UIImage alloc] initWithContentsOfFile:path];
			UIImageView *haiyo = [haikei objectAtIndex:w];  //NSMutableArray  haikei に背景のオブジェクトを登録して使ってた
			haiyo.image = imag;
		}
	}
}

shakeView.m

#import "ShakeView.h"


@implementation ShakeView

- (BOOL)canBecomeFirstResponder {
	return YES;
}

- (id)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code.
    }
    return self;
}