dimanche 22 février 2015

Image Shutters When It Moves From TouchesBegan

When I used this code I made to move the image up and down by tapping up or down, there seems to be this shutter when the image is moving. The code shows that the user has to tap the top or bottom of the screen to move the image. There is also a rate the image moves by but changing the rate doesn't fix the shutter. Here's the code:



//.h
int ImageMovement;
@interface ViewController : UIViewController{

IBOutlet UIImageView *Image;

NSTimer *DotMove;
}

@end

//.m
-(void)viewDidLoad{

ImageMove = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(Movement) userInfo:nil repeats:YES];

}


-(void)Movement{

Image.center = CGPointMake(Image.center.x, Image.center.y + ImageMovement);

}
-(void)returnImage {

Image.center = CGPointMake(ImageDot.center.x, ImageMovement +5);

}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

UITouch *touch= [touches anyObject];
CGPoint point = [touch locationInView: self.view];

if (point.y < 275) {
ImageMovement=-10.5;

}

else
ImageMovement = 10.5;

}


-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

ImageMovement = 0;

}

Aucun commentaire:

Enregistrer un commentaire