AUTORESize UIScrollView
-
27-09-2019 - |
Pergunta
Eu fiz um UIViewController, que gera programaticamente um UIScrollView. Está tudo bem, mas quando eu giro o dispositivo, o UISCOLLVIEW deve redimensionar, para que seja a largura completa da minha opinião.
Existe uma maneira de fazer isso sem reconstruir o UiscrollView completo?
Muito obrigado! Sebastian
Isso é chamado no meu ViewDidload:
-(void)buildmyScroller {
myScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 800, 768, 100)];
//...adding some subviews to myScroller
thumbScroller.contentSize = CGSizeMake(3000, 100);
[[self view] addSubview:myScroller];
}
Então tentei redimensionar o MyScroller com isso, quando usei o SetFrame, disse que o MyScroller não respondia a isso ...:
-(void)changemyScroller {
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
[thumbScroller setFrame:CGRectMake(0, 805, 768, 150)];
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
thumbScroller.frame = CGRectMake(0, 805, 768, 150);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
thumbScroller.frame = CGRectMake(0, 549, 1024, 150);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
thumbScroller.frame = CGRectMake(0, 549, 1024, 150);
}
}
E chamou o método no DiDanimateFirstalf ... porque não estou mais curto para onde chamá -lo.
Muito obrigado novamente !!
Solução
scrollView setFrame: cGrectmake (x, y, largura, altura)]; // Talvez você precise fazer o mesmo para o conteúdo do ScrollView para fazê -lo se encaixar no seu layout
deve fazer isso. Você pode embrulhar isso em um bloco de uianimação se precisar ser uma transição.
Outras dicas
Experimente isso:
if(self.rowNumber == 0){
/******************* Scroller Setup *****************/
// how many pages
int pageCount = 5;
//set up the scrollView
UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 960)];
// support for Landscape Orienation
if(UIInterfaceOrientationLandscapeLeft){
[scroller setFrame:CGRectMake(0,0,1024, 704)];
}
if(UIInterfaceOrientationLandscapeRight){
[scroller setFrame:CGRectMake(0,0,1024, 704)];
}