超過1個圖像我試圖在滾動型添加圖片。我有一個plist文件中的x和y點,它們被一個枚舉調用。上一個子視圖不加載
enum {
kLogoImage = 1,
kNewLogoImage,
};
@implementation
- (void) _setupStaticViews
{
UIButton *image = [UIButton buttonWithType:UIButtonTypeCustom];
[image setBackgroundImage:[UIImage imageNamed:@"logo.png"] forState:UIControlStateNormal];
[image addTarget:self action:@selector(_addContactButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
image.frame = CGRectMake(0.0 ,0.0, 150.0, 150.0);
image.tag = kLogoImage;
[_mapImageView addSubview:image];
_staticViews = @[image];
UIButton *image2 = [UIButton buttonWithType:UIButtonTypeCustom];
[image2 setBackgroundImage:[UIImage imageNamed:@"Time Bakground.png"] forState:UIControlStateNormal];
[image2 addTarget:self action:@selector(_addContactButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
image2.frame = CGRectMake(0.0 ,0.0, 250.0, 150.0);
image2.tag = kNewLogoImage;
[_mapImageView addSubview:image2];
_staticViews = @[image2];
for (UIView *view in _staticViews) {
CGPoint point = [self _basePositionForView:view];
CGRect frame = view.frame;
frame.origin = point;
view.frame = frame;
}
}
如果我只有圖像顯示,它工作正常。但是我需要添加多個,並且添加第二個導致第一個導致xy點0,0,並且Image2不可見。 我將如何去添加另一個圖像?
- (CGPoint) _basePositionForView:(UIView *)view {
NSString *key = [NSString stringWithFormat:@"%d", view.tag];
NSString *stringValue = [_coordinates objectForKey:key];
NSArray *values = [stringValue componentsSeparatedByString:@":"];
if ([values count] < 2) return CGPointZero;
CGPoint result = CGPointMake([[values objectAtIndex:0] floatValue], [[values objectAtIndex:1] floatValue]);
return result;
}
_basePositionForView的代碼是什麼:? –
加入問題。 – PappaSmalls
好,最後一個 - 有機會偷看_coordinates? –