【发布时间】:2015-01-28 22:31:54
【问题描述】:
我对 Xcode 和 iOS 开发相当陌生,但到目前为止我一直很享受挑战。
我遇到了一个问题,我试图移动一个UIImageView 我以编程方式在 MapBox 地图视图之上创建。
我想将这个UIImageView 和UIButton 移动一个像素,UIButton 位于mapView 的顶部。
这是我目前在 ViewController.m 中的代码:
[self.view addSubview:mapView];
UIImageView* ship;
ship=[[UIImageView alloc] initWithFrame:CGRectMake(150, 200, 40, 40)];
UIImage * image;
image=[UIImage imageNamed:@"spaceShip"];
[ship setImage:image];
ship.alpha = 0.75;
[self.view addSubview:ship];
UIButton *upButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
upButton.frame = CGRectMake(150, 250, 40, 40);
upButton.userInteractionEnabled = YES;
[upButton setTitle:@"UP" forState:UIControlStateNormal];
[upButton addTarget:ship action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:upButton];
}
- (IBAction)moveUp {
ship.center = CGPointMake(ship.center.x, ship.center.y -10);
}
谁能告诉我如何让这个 upButton 识别和移动我的UIImageView?
【问题讨论】:
标签: ios uiimageview uibutton mapbox