2015-11-10 44 views
0

我在我的应用程序中有一个UIScrollView,我想基本上在最后一页上添加一个按钮。现在,我在滚动视图下添加故事板中的按钮,并将该按钮的X参数设置为1050,即屏幕宽度为320(iPhone5)的screenWidth * 3 + 90。所以,你可以看到它可以在iPhone5上运行,但不适用于大屏幕6/6Plus。我试图以编程方式重新调整按钮,但它不起作用。添加一个按钮到UIScrollView的最后一页

-(void)viewDidAppear:(BOOL)animated 
{ 
    ... 


    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 
    CGFloat screenHeight = screenRect.size.height; 

    [self.tutorialScrollView addSubview:page1]; 
    [self.tutorialScrollView addSubview:page2]; 
    [self.tutorialScrollView addSubview:page3]; 
    [self.tutorialScrollView addSubview:page4]; 

    [self.tutorialScrollView setContentSize:CGSizeMake(screenWidth*4, screenHeight)]; 

    //readjust button 

    CGRect btFrame = self.tutorialFinish.frame; //self.tutorialFinish is a UIButton 
    btFrame.origin.x = (90 + screenWidth * 3); 
    btFrame.origin.y = 492/568 * screenHeight; 
    self.tutorialFinish.frame = btFrame; 
} 

回答

0

尝试调整BTN的center

self.tutorialFinish.center = CGPointMake(90 + screenWidth * 3 + self.tutorialFinish.frame.size.width/2, 
              492/568 * screenHeight + self.tutorialFinish.frame.size.height/2);; 
+0

nope仍然不起作用 – stud91

+0

会发生什么?位置不正确? – anhtu

+0

是的按钮出现在第三页..以前它是什么 – stud91

0

你应该换你UIScrollView与其他一些UIView知道屏幕尺寸。稍后您可以自动将它传递给您的滚动视图,如layoutView。在代码中,我的意思是,我不知道如何在Storyboard中做这样的事情,但我认为这是可能的。

从那时起,您应该可以将视图调整为任何现有或未来的屏幕尺寸。

0
CGRect buttonFrame = CGRectMake(screenwidth * (page-1)+ (screenwidth 
-self.button.frame.size.width)/2, y position, button width, button height); 
相关问题