2012-11-19 127 views
1

超過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; 
} 

+0

_basePositionForView的代碼是什麼:? –

+0

加入問題。 – PappaSmalls

+0

好,最後一個 - 有機會偷看_coordinates? –

回答

1

我注意到,你首先要

_staticViews = @[image]; 

後來

_staticViews = @[image2]; 

你難道不頗具意味有

_staticViews = @[image, image2]; 

+0

就是這樣!我知道這是一個愚蠢的錯誤,謝謝。 – PappaSmalls

+1

它發生,很高興我可以幫助:) –

0

你應該重複和變化框架相應X:

for (int iterator=0; iterator< [[_staticViews subviews] count]; iterator++){ 
...  
current_image.frame = CGRectMake(YOUR_IMG_WIDTH * iterator ,0.0, YOUR_IMG_WIDTH, 150.0); 
...} 
+0

同樣的問題,只有現在第一個圖像有一個位置,並且它覆蓋了plist文件。 frame = CGRectMake(150.0 *迭代器,1000.0,150.0,150.0); image2.frame = CGRectMake(150.0 *迭代器,0.0,250.0,250.0); }' - – PappaSmalls