2009-12-17 69 views
0

我试图添加UIButtonUIScrollView添加一个UIButton到的UIScrollView

我已经添加了与UIImageView背景图像*(尺寸:320×620)*。 然后我说这个UIImageViewUIScrollView,并能正常工作。

但现在我想添加UIButton在位置:(60,500);(以下滚动后似乎该屏幕)。

我试过下面的代码,但是在UIView上加上的按钮不在scrollview上。按钮是没有得到显示在顶部。

代码:

- (void)viewDidLoad  
{  
    [super viewDidLoad]; 
    self.navigationController.navigationBar.hidden = TRUE; 

    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SingleModelVar.png"]]; 
    self.imageView = tempImageView; 
    [tempImageView release]; 

    imageView.userInteractionEnabled = YES; 

    scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; //fit to screen 

    //scrollView.delaysContentTouches = NO; 

    scrollView.contentSize = CGSizeMake(320, imageView.frame.size.height);   //imageView.frame.size.height=620 here 
    scrollView.maximumZoomScale = 4.0; 
    scrollView.minimumZoomScale = 0.75; 
    scrollView.clipsToBounds = YES; 
    scrollView.delegate = self; 

    //The Problem begins .......... 

    btnStartDate=[[UIButton alloc] initWithFrame:CGRectMake(60,500,100,20)]; 
    [scrollView addSubview:btnStartDate]; 
    //[self.view addSubview:btnStartDate]; 

    btnEndDate=[[UIButton alloc] initWithFrame:CGRectMake(60,530,100,20)]; 
    [scrollView addSubview:btnEndDate]; 
    //[self.view addSubview:btnEndDate]; 

    [scrollView addSubview:imageView]; 
    [[self view] addSubview:scrollView]; 
} 

回答

1

,因为你加入他们,你添加的ImageView之前它不显示在顶部。 btnStartDate=[[UIButton alloc] initWithFrame:CGRectMake(60,500,100,20)];

之前把 [scrollView addSubview:imageView];