旋转木马倾斜效果

    self._iCarouse.viewpointOffset=CGSizeMake(0,-250);
    self._iCarouse.contentOffset=CGSizeMake(0,-250);

其他都不用变,就在viewDidLoad中添加这两句就行了





- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden=YES;
    carousel=[[iCarousel alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
carousel.delegate = self;
    carousel.dataSource = self;
    carousel.type = iCarouselTypeRotary;
    //设置背景图片。
    UIImageView *bgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    bgView.image=[UIImage imageNamed:@"background_home.png"];
    [self.view addSubview:bgView];
    [self.view addSubview:carousel];
    self.carousel.viewpointOffset=CGSizeMake(0,-250);
    self.carousel.contentOffset=CGSizeMake(0,-250);
   
}

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return 5;
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
    UIView *view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",index]]] autorelease];
 
    view.frame = CGRectMake(0, 93, 105, 123);
    return view;
}

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
return 0;
}

- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
    return 5;
}

- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
    return 150;
}
- (UIView *)itemViewAtIndex:(NSInteger)index{
    UIView *view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",index]]] autorelease];
    if (index==0) {
        view.frame=CGRectMake(0, 0, 4, 3);
    }
    if (index==1) {
        view.frame=CGRectMake(0, 0, 114, 113);
    }
    if (index==2) {
        view.frame=CGRectMake(0, 0, 94, 93);
    }
    if (index==3) {
        view.frame=CGRectMake(0, 0, 74, 73);
    }
    else{
        view.frame = CGRectMake(1, 75, 130, 120);
    }
   
    //    view.frame = CGRectMake(0, -500, 320, 800);
    return view;
}
- (CATransform3D)carousel:(iCarousel *)_carousel transformForItemView:(UIView *)view withOffset:(CGFloat)offset
{
    view.alpha = 1.0 - fminf(fmaxf(offset, 0.0), 1.0);
   
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = self.carousel.perspective;
    transform = CATransform3DRotate(transform, M_PI / 8.0, 0, 1.0, 0);
    return CATransform3DTranslate(transform, 0.0, 0.0, offset * carousel.itemWidth);
}
//这就相当于tableview的点击事件。
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index{
    NSLog(@"%d",index);
    if (index==1) {//域名查询
        CheckDNS *check=[[CheckDNS alloc]init];
        [self.navigationController pushViewController:check animated:YES]; 
    }
    if (index==2) {//解析管理。
        Jiexiguanli *jiexi=[[Jiexiguanli alloc]initWithNibName:@"Jiexiguanli" bundle:nil];
        [self.navigationController pushViewController:jiexi animated:YES]; 
    }
    if (index==3) {//域名体检
        DomainCheckViewController *domain=[[DomainCheckViewController alloc]init];
        [self.navigationController pushViewController:domain animated:YES]; 
    }
    if (index==4) {//域名咨询。
        InformationViewController *infor=[[InformationViewController alloc]initWithNibName:@"InformationViewController" bundle:nil];
        [self.navigationController pushViewController:infor animated:YES]; 
    }
    if (index==0) {//设置。
        SetViewController *set=[[SetViewController alloc]init];
        [self.navigationController pushViewController:set animated:YES]; 
    }
}


猜你喜欢

转载自zhangmingwei.iteye.com/blog/1743810