0
我以编程方式在xCode中插入自定义图像(图像)。点击UI按钮后,我想将按钮移动到iPhone屏幕上的自定义位置。点击按钮后移动图像
的编程按钮:
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIButton *MyButton = [UIButton buttonWithType:nil];
MyButton.frame = CGRectMake(100, 170, 100, 30);
[MyButton setImage:[UIImage imageNamed:@"tap.png"] forState:nil];
[self.view addSubview:MyButton];
[MyButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
我试图点击后移动的按钮。
-(void)buttonPressed {
NSLog(@"Button Pressed!");
CGRect frame = MyButton.frame;
frame.origin.x = 100; // new x coordinate
frame.origin.y = 4; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 0.1];
MyButton.frame = frame;
[UIView commitAnimations];
}
但是没有发生任何事情。
我的.h
文件
IBOutlet UIButton *MyButton;
@property (nonatomic, retain) UIButton *MyButton;
哎呀对不起图像是costum的UIButton – Frenck 2012-03-16 19:02:34
你能对你有确切的问题推断?看起来你非常接近。 – FreeAsInBeer 2012-03-16 19:15:21
我编辑了消息@FreeAsInBeer希望你能帮助我 – Frenck 2012-03-16 19:28:59