iCarousel
视图在屏幕方向更改期间调整放置在轮播视图中的项目时出现问题。我该如何解决此问题?
这是我的代码
- ( void ) handleOrientation:(UIInterfaceOrientation )toInterfaceOrientation {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
orient = YES;
_deptCarousel.center = CGPointMake(390, 628);
}else {
orient = NO;
_deptCarousel.center = CGPointMake(512, 455);
}
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
//create a numbered view
UIView *viewBG = nil;
viewBG = [[UIImageView alloc]initWithImage:[UIImage imageNamed:IS_IPAD?@"Scroll_Placeholder_ImageiPad.png":@"Carousel_Placeholder_Image.png"]];
if (IS_IPAD) {
if (orient) {
viewBG.frame = CGRectMake(0, 0, 420, 350);
}else{
viewBG.frame = CGRectMake(0, 0, 380, 280);
}
} else {
viewBG.frame = CGRectMake(0, 0, 210, 170);
}
}
答案 0 :(得分:2)
为了更改框架,您应该在Orientation方法中重新加载轮播,否则它不会影响它。
- ( void ) handleOrientation:(UIInterfaceOrientation )toInterfaceOrientation {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
orient = YES;
_deptCarousel.center = CGPointMake(390, 628);
//reload your Carousel
}else {
orient = NO;
_deptCarousel.center = CGPointMake(512, 455);
//reload your Carousel
}
}
答案 1 :(得分:2)
我认为您在首次加载iCarousel
时已检查了设备方向。只要您的方向发生变化,您就必须检查并调整Carousel
视图的大小。因此,请尝试在下面的方向委托中检查它。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (IS_IPAD) {
if (orient) {
viewBG.frame = CGRectMake(0, 0, 420, 350);
}else{
viewBG.frame = CGRectMake(0, 0, 380, 280);
}
}
[_deptCarousel reloadData];
return YES;
}
我认为它可能对你有所帮助。如果您对此有任何疑问,请与我们联系。
谢谢。