How to move image in UIView
1. UIView define
2. UIScrollView define
3. UIImageView define
4. UIimage define
.h file
...
UISCrollView *scView;
...
@propery (nonautomic, retain) IBOutlet UIScrollView *scView;
.m file
..
@synthesize scView;
..
-(void)viewDidLoad
{
UIImage *image = [UIImage imageNamed:@"test.png"];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[scView addSubview:imageview];
// repeat 1 second
[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(imagemove:) userInfo:nil repeat:YES];
}
-(void)imagemove:(NSTimer *)timer {
CGRect bounds;
bounds = scView.bounds;
bounds = CGRectMake(scView.bounds.origin.x - 1.0f, scView.bounds.origin.y, scView.bounds.size.width, scView.bounds.size.height);
scView.bounds = bounds;
}
test Result is OK....
2. UIScrollView define
3. UIImageView define
4. UIimage define
.h file
...
UISCrollView *scView;
...
@propery (nonautomic, retain) IBOutlet UIScrollView *scView;
.m file
..
@synthesize scView;
..
-(void)viewDidLoad
{
UIImage *image = [UIImage imageNamed:@"test.png"];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[scView addSubview:imageview];
// repeat 1 second
[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(imagemove:) userInfo:nil repeat:YES];
}
-(void)imagemove:(NSTimer *)timer {
CGRect bounds;
bounds = scView.bounds;
bounds = CGRectMake(scView.bounds.origin.x - 1.0f, scView.bounds.origin.y, scView.bounds.size.width, scView.bounds.size.height);
scView.bounds = bounds;
}
test Result is OK....
댓글
댓글 쓰기