这就是你所描述的情况吗?因为它看起来工作得很好。您是否检查了 UIView 上的 userInteractionEnabled 是否设置为 YES?
- (void)buttonPressed:(UIButton*)button
{
NSLog(@"button pressed");
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, -100, 100, 100)];
view.backgroundColor = [UIColor blackColor];
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Button" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 10, 100, 20);
[view addSubview:button];
[self.view addSubview:view];
[UIView animateWithDuration:0.5 animations:^{
view.transform = CGAffineTransformMakeTranslation(0, 100);
}];
[view release];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3602 次 |
| 最近记录: |