我有imageView
并且在其中我放了一个按钮。我有两个问题:
imageView
来为视图设置动画?代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *grayFrame = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"expSqrGray.png"]];
[self.view addSubview:grayFrame];
grayFrame.frame = CGRectOffset(grayFrame.frame, 0, 0);
UIButton *testButton = [UIButton buttonWithType:UIButtonTypeCustom];
testButton.frame = CGRectMake(20, 20, 200, 44);
testButton.backgroundColor = [UIColor blackColor];
[testButton setTitle:@"Test" forState:UIControlStateNormal];
[testButton addTarget:self action:@selector(tapped:) forControlEvents:UIControlEventTouchUpInside];
[grayFrame addSubview:testButton];
//[self.view addSubview:testButton];
}
答案 0 :(得分:1)
我对Objective-C几乎没有任何了解,但您可能想要做的是制作班级的grayFrame
和testButton
成员变量。这样,您的整个班级都可以访问这两个对象。
例如:
// Test.H
@interface YourClass : NSObject {
UIImageView * grayFrame;
UIButton * testButton;
}
然后,您可以使用另一种方法来引用其中任何一种方法。
- (void) initializeObjects {
grayFrame = [ [ UIImageView alloc ] initWithImage:[ UIImage imageNamed:@"expSqrGray.png" ] ];
testButton = [ UIButton buttonWithType:UIButtonTypeCustom ];
// Do things here.
}