Autoresize UisCrollView
-
27-09-2019 - |
سؤال
لقد صنعت UiviewController ، والذي يولد برمجيًا مجموعة uiscrollview. كل شيء على ما يرام ، ولكن عندما أقوم بتدوير الجهاز ، يجب أن يتم تغيير حجم Uiscollview بحيث يتطلب العرض الكامل لرأيي.
هل هناك طريقة للقيام بذلك دون إعادة بناء Uiscrollview الكاملة؟
شكرا جزيلا! سيباستيان
وهذا ما يسمى في lipedidload:
-(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];
}
ثم حاولت تغيير حجم myscroller بهذا ، عندما استخدمت setFrame ، قلت إن Myscroller لن يرد عليه ...:
-(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);
}
}
ودعا الطريقة في didanimatefirsthalf ... لأنني لست متشوقًا في أي مكان آخر أسميه.
شكرا جزيلا مرة أخرى !!
المحلول
ScrollView SetFrame: CgrectMake (X ، Y ، العرض ، الارتفاع)] ؛ // ربما تحتاج إلى فعل الشيء نفسه لمحتوى ScrollView لجعله يناسب تخطيطك
يجب القيام به. يمكنك لف ذلك في كتلة uianimation إذا كان بحاجة إلى أن يكون انتقالًا.
نصائح أخرى
جرب هذا:
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)];
}