项目用到的icarouls类和UIEffectDesignerView类,菜单技巧,构思(金方圆)

高宇定
2023-12-01

//

//  MenuHomeViewController.m

//  HFYS

//

//  Created by Showsoft_002 on 13-8-14.

//  Copyright (c) 2013年 Showsoft_002. All rights reserved.

//

 

#import "MenuHomeViewController.h"

#import "MainControlViewController.h"

#import "iCarousel.h"

#import "AssitentTimer.h"

#import "ContentPageViewController.h"

#import "ItemsSubViewIndex.h"

#import "UIEffectDesignerView.h"

#import "CalculatorViewController.h"

#import "JiSuanQiViewController.h"

 

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

 

#define NUMBER_OF_ITEMS (IS_IPAD? 19: 12)

#define NUMBER_OF_VISIBLE_ITEMS 5

#define ITEM_SPACING 77

#define INCLUDE_PLACEHOLDERS NO

 

typedefenum {

    items_BrandHomeView = 0 ,

    items_TraficHomeView,

    items_ProjectHomeView ,

    items_PropertyShowView,

    items_CalulatorShowView,

}ItemsViewControllerNameEnum;

 

@interfaceMenuHomeViewController ()<iCarouselDataSource , iCarouselDelegate,AsstentTimerDelegate>{

    UIImageView *backImageView;

    

    int subViewIndex;

    iCarousel *myIcarousel;

    NSArray *contentArray;

    

    

    JiSuanQiViewController *jisuanqiView;

    

    ContentPageViewController *contentPageView;

    CGRect remberFrame;

    

    NSTimer *animationTimer;

}

-(void)calButtonAction:(UIButton *)sender;

@end

 

@implementation MenuHomeViewController

 

- (void)dealloc{

    if( contentPageView ){

        [contentPageView.viewremoveFromSuperview];

        contentPageView = nil;

    }

    

    myIcarousel.delegate = nil;

    myIcarousel.dataSource = nil;

    [myIcarouselremoveFromSuperview];

    myIcarousel = nil ;

    

    contentArray = nil ;

    

    [backImageViewremoveFromSuperview];

    backImageView = nil ;

    

    [selfstopMenuTimer];

}

 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    returnself;

}

 

- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view.

    backImageView = [[UIImageViewalloc]initWithFrame:CurrentDeviceBounds];

    backImageView.userInteractionEnabled = YES ;

    backImageView.tag = 1 ;

    [self.viewaddSubview:backImageView];

    

    UIEffectDesignerView* effectView = [UIEffectDesignerVieweffectWithFile:@"StartPage.ped"];

    [backImageView addSubview:effectView];

    

    

    contentArray = [NSArrayarrayWithObjects:

                    SSENCRYPTED_IMAGE(@"Item_pic1.png"),SSENCRYPTED_IMAGE(@"Item_pic2.png"),SSENCRYPTED_IMAGE(@"Item_pic3.png"),SSENCRYPTED_IMAGE(@"Item_pic4.png"),SSENCRYPTED_IMAGE(@"Item_pic5.png"),

                    nil];

    

//    myIcarousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, 670/2 , 1024, 300)];//CGRectMake(0, 392/2-150, 790, 515)

//    myIcarousel.type = iCarouselTypeCylinder;

//    myIcarousel.delegate = self;

//    myIcarousel.dataSource = self;

//    //add carousel to view

//    [backImageView addSubview:myIcarousel];

    

}

 

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (void)enterAnimationWhenAppear{

    float delayTimes = 0;

    GYLWhiteMaskView *logo = [self addLogoWithFrame:CGRectMake((1024-216)/2, 126/2, 216, 185) inView:backImageView];

    [selfgeneryallyAnimationWithView:logo animationType:GenerallyAnimationSliderFormTopduration:0.3delayTime:delayTimes finishedBlock:nil];

    

    delayTimes += 0.3;

    NSArray *array = [NSArray arrayWithObjects:

                      [NSValue valueWithCGPoint:CGPointMake(926/2, 672/2)],@"Item_pic3.png",

                      [NSValue valueWithCGPoint:CGPointMake(656/2, 730/2)],@"Item_pic2.png",

                      [NSValue valueWithCGPoint:CGPointMake(1224/2, 730/2)],@"Item_pic4.png",

                      [NSValue valueWithCGPoint:CGPointMake(406/2, 766/2)],@"Item_pic1.png",

                      [NSValue valueWithCGPoint:CGPointMake(1488/2, 766/2)],@"Item_pic5.png",

                      nil];

    for( int i=0;i<5;i++ ){

        NSString *string = [array objectAtIndex:2*i+1];

        UIImage *locImage = SSENCRYPTED_IMAGE(string);

        CGRect framess ;

        framess.origin = [[array objectAtIndex:2*i] CGPointValue];

        framess.size = locImage.size;

        UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

        button.frame = framess;

        button.tag = 100 + i ;

        [button setBackgroundImage:locImage forState:UIControlStateNormal];

        [button addTarget:selfaction:@selector(itemsButtonAction:) forControlEvents:UIControlEventTouchUpInside];

        [backImageView addSubview:button];

        

        [selfpopAnimationAndRoateWithView:button delayTime:delayTimes];

        if( i%2 == 0 ) delayTimes += 0.6 ;

    }

    

    UIButton *backHomeButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

    backHomeButton.frame = CGRectMake((1024-146)/2, 1374/2 - 20, 146, 20+40);

    [backHomeButton setImage:SSENCRYPTED_IMAGE(@"BackHomeButton.png") forState:UIControlStateNormal];

    [backHomeButton addTarget:selfaction:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    [backImageView addSubview: backHomeButton];

    

    [selfgeneryallyAnimationWithView:backHomeButton animationType:GenerallyAnimationSliderFormBottomduration:0.3delayTime:delayTimes finishedBlock:nil];

    

    UIButton *calButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

    calButton.frame = CGRectMake(1906/2 - 10, 32/2-10, 36+20, 36+20);

    [calButton setImage:SSENCRYPTED_IMAGE(@"CalclutorBtn.png") forState:UIControlStateNormal];

    [calButton addTarget:selfaction:@selector(calButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    [backImageView addSubview:calButton];

    

    [selfgeneryallyAnimationWithView:calButton animationType:GenerallyAnimationSliderFormTopduration:0.3delayTime:delayTimes finishedBlock:nil];

    

    [selfstartAssitentTimer];

    

    [selfstartMenuTimer];

}

-(void)startMenuTimer{

    //定时翻转列表

    animationTimer = [NSTimerscheduledTimerWithTimeInterval:3target:selfselector:@selector(timeAction:) userInfo:nilrepeats:YES];

}

-(void)stopMenuTimer{

    //释放Timer

    if (animationTimer) {

        [animationTimerinvalidate];

        animationTimer = nil;

    }

}

//定时器事件

-(void)timeAction:(id)sender

{

    NSLog(@"time");

    [selfstartItemAnimation:YES];

}

//播放列表动画

-(void)startItemAnimation:(BOOL)isLeft

{

    int count=5;

    if(!isLeft)

    {

        for (int i=0; i<count; i++) {

            [UIViewanimateWithDuration:0.7delay:0.2*i options:UIViewAnimationOptionCurveEaseInOutanimations:^{

                

                UIView *parentView = [backImageView viewWithTag:100+(count-1 -i)];

                //设置动画效果

                [UIViewsetAnimationTransition: UIViewAnimationTransitionFlipFromRightforView:parentView cache:NO];  //从上向下

            }completion:nil];

        }

    }else

    {

        for (int i=0; i<count; i++) {

            [UIViewanimateWithDuration:0.7delay:0.2*i options:UIViewAnimationOptionCurveEaseInOutanimations:^{

                UIView *parentView = [backImageView viewWithTag:100+i];

                //设置动画效果

                [UIViewsetAnimationTransition: UIViewAnimationTransitionFlipFromLeftforView:parentView cache:NO];  //从上向下

            }completion:nil];

        }

    }

}

- (void)popAnimationAndRoateWithView:(UIView *)animationView delayTime:(float)delayTime{

    __weakMenuHomeViewController *weakSelf = self ;

    [selfgeneryallyAnimationWithView:animationView animationType:GenerallyAnimationPopOutduration:0.3delayTime:delayTime finishedBlock:^{

        [weakSelf roateAnimationWithView:animationView];

    }];

}

 

- (void)roateAnimationWithView:(UIView *)animaitonView{

    [UIViewanimateWithDuration:0.7delay:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{

        

        //设置动画效果

        [UIViewsetAnimationTransition: UIViewAnimationTransitionFlipFromLeftforView:animaitonView cache:NO];  //从上向下

    }completion:nil];

}

 

- (void)backButtonAction:(UIButton *)sender{

    UIResponder *sponder = [selfcheckNextResponderIsKindOfViewController:[MainControlViewControllerclass]];

    if( sponder ){

        MainControlViewController *lfc = (MainControlViewController *)sponder ;

        [lfc transViewToHomePageView];

    }

}

 

- (void)playVideoAction:(UIButton *)sender{

    UIResponder *sponder = [selfcheckNextResponderIsKindOfViewController:[MainControlViewControllerclass]];

    if( sponder ){

        MainControlViewController *lfc = (MainControlViewController *)sponder ;

        [lfc transViewToVideoView];

    }

}

 

- (void)calculatorButtonAction:(UIButton *)sender{

    if( contentPageView ) return ;

    

    remberFrame = sender.frame ;

    

    contentPageView = [[ContentPageViewControlleralloc]init];

    contentPageView.transIndex = PageSix_Title;

    contentPageView.view.frame = CurrentDeviceBounds;

    [self.viewaddSubview:contentPageView.view];

    

    [selffallInTransitionToView:contentPageView.viewwith:backImageViewanimationTime:0.5transContent:nilcompletion:^{

        [contentPageViewenterAnimationWhenAppear];

    }];

}

 

- (void)releaseAddSubView{

    

    if(jisuanqiView)

    {

        [selfgeneryallyAnimationWithView:jisuanqiView.viewanimationType:GenerallyAnimationFadeOutduration:.5delayTime:0finishedBlock:^{

            [jisuanqiView.viewremoveFromSuperview];

            jisuanqiView=nil;

        }];

    }

    

    if( !contentPageView ) return ;

    backImageView.alpha = 1 ;

    backImageView.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(0.0) , 1.f , 1.f);

    

    [selfbackTransitionWithView:contentPageView.viewto:backImageViewtransFrame:remberFrameanimationTime:0.5transContent:nilcompletion:^{

        [contentPageView.viewremoveFromSuperview];

        contentPageView = nil;

        

        [selfstartAssitentTimer];

        [selfstartMenuTimer];

    }];

}

 

- (void)startAssitentTimer{

//    [[self.view viewWithTag:123456] removeFromSuperview];

//    

//    AssitentTimer *locView = [[AssitentTimer alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];

//    locView.userInteractionEnabled = NO ;

//    locView.tag = 123456;

//    locView.myDelegate = self ;

//    [self.view insertSubview:locView atIndex:0];

//    

//    [locView startTimerWithTime:3 isLoop:YES];

}

 

- (void)assitentTimerEndWithCurrentView:(UIView *)currentView{

//    int nums = myIcarousel.currentItemIndex;

//    nums ++ ;

//    if( nums >= [contentArray count]*2 ){

//        nums = 0 ;

//    }

//    

//    [myIcarousel scrollToItemAtIndex:nums animated:YES];

}

 

- (void)stopAssitentTimer{

//    [[self.view viewWithTag:123456] removeFromSuperview];

}

 

#pragma mark -

#pragma mark iCarousel methods

 

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel

{

    return [contentArraycount]*2;

}

 

- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel

{

    //limit the number of items views loaded concurrently (for performance reasons)

    returnNUMBER_OF_VISIBLE_ITEMS;

}

 

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view

{

//create new view if no view is available for recycling

    if (view == nil)

    {

        view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ITEM_SPACING, myIcarousel.bounds.size.height)];

        view.clipsToBounds = NO ;

        

        UIImageView *downImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 77, 200)];

        downImageView.tag = 10 ;

        [view addSubview:downImageView];

    }

    

    UIImageView *downImageView = (UIImageView *)[view viewWithTag:10];

    //    NSString *string = [downImageArray objectAtIndex:index % 4];

    downImageView.image = [contentArray objectAtIndex:index%5 ];

    

    return view;

}

 

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel

{

//note: placeholder views are only displayed if wrapping is disabled

returnINCLUDE_PLACEHOLDERS? 2: 0;

}

 

- (CGFloat)carouselItemWidth:(iCarousel *)carousel

{

    //slightly wider than item view

    returnITEM_SPACING;

}

 

- (BOOL)carouselShouldWrap:(iCarousel *)carousel

{

    //wrap all carousels

    returnYES;

}

- (CGFloat)carousel:(iCarousel *)carousel itemAlphaForOffset:(CGFloat)offset

{

//set opacity based on distance from camera

    return 1.0f - fminf(fmaxf(offset, 0.0f), 1.0f);

}

 

- (CATransform3D)carousel:(iCarousel *)_carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform

{

    //implement 'flip3D' style carousel

    transform = CATransform3DRotate(transform, M_PI / 8.0f, 0.0f, 1.0f, 0.0f);

    return CATransform3DTranslate(transform, 0.0f, 0.0f, offset * myIcarousel.itemWidth);

}

- (CGFloat)carousel:(iCarousel *)carousel valueForTransformOption:(iCarouselTranformOption)option withDefault:(CGFloat)value

{

    switch (option)

    {

        caseiCarouselTranformOptionArc:

        {

            return 2 * M_PI * 0.1;

        }

        caseiCarouselTranformOptionRadius:

        {

            return value * 1.8;

        }

        caseiCarouselTranformOptionTilt:

        {

            return 0.5;

        }

        caseiCarouselTranformOptionSpacing:

        {

            return 1;

        }

        default:

        {

            return value;

        }

    }

}

 

- (void)carouselWillBeginDragging:(iCarousel *)carousel{

    [selfstopAssitentTimer];

}

 

- (void)carouselDidEndDragging:(iCarousel *)carousel willDecelerate:(BOOL)decelerate{

    [selfstartAssitentTimer];

}

 

- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index{

    if( contentPageView ) return ;

    

    [selfstopAssitentTimer];

    

    NSArray *array = [NSArray arrayWithObjects:

                      [NSNumber numberWithInt:PageOne_Title],

                      [NSNumber numberWithInt:PageTwo_Title],

                      [NSNumber numberWithInt:PageThree_Title],

                      [NSNumber numberWithInt:PageFour_Title],

                      [NSNumber numberWithInt:PageFive_Title],

                      nil];

    int nums = index % 5 ;

    UIView *locView = [myIcarousel itemViewAtIndex:index];

    UIImageView *imageView = (UIImageView *)[locView viewWithTag:10];

    remberFrame = [locView convertRect:imageView.frame toView:backImageView];

    NSLog(@"remberFrame is %@" , NSStringFromCGRect(remberFrame));

    

    contentPageView = [[ContentPageViewControlleralloc]init];

    contentPageView.transIndex = [[array objectAtIndex:nums] integerValue];

    contentPageView.view.frame = CurrentDeviceBounds;

    [self.viewaddSubview:contentPageView.view];

    

    [selffallInTransitionToView:contentPageView.viewwith:backImageViewanimationTime:0.5transContent:nilcompletion:^{

        [contentPageViewenterAnimationWhenAppear];

    }];

}

 

- (void)itemsButtonAction:(UIButton *)sender{

    int index = sender.tag % 100 ;

    if( contentPageView ) return ;

    

    [selfstopAssitentTimer];

    

    NSArray *array = [NSArray arrayWithObjects:

                      [NSNumber numberWithInt:PageThree_Title],

                      [NSNumber numberWithInt:PageTwo_Title],

                      [NSNumber numberWithInt:PageFour_Title],

                      [NSNumber numberWithInt:PageOne_Title],

                      [NSNumber numberWithInt:PageFive_Title],

                      nil];

    int nums = index % 5 ;

    remberFrame = sender.frame;

    NSLog(@"remberFrame is %@" , NSStringFromCGRect(remberFrame));

    

    contentPageView = [[ContentPageViewControlleralloc]init];

    contentPageView.transIndex = [[array objectAtIndex:nums] integerValue];

    contentPageView.view.frame = CurrentDeviceBounds;

    [self.viewaddSubview:contentPageView.view];

    

    [selffallInTransitionToView:contentPageView.viewwith:backImageViewanimationTime:0.5transContent:nilcompletion:^{

        [contentPageViewenterAnimationWhenAppear];

    }];

    [selfstopMenuTimer];

}

 

//计算器

-(void)calButtonAction:(UIButton *)sender

{

    if( contentPageView ) return ;

    remberFrame = sender.frame;

    contentPageView = [[ContentPageViewControlleralloc]init];

    contentPageView.transIndex = PageSix_Title;

    contentPageView.view.frame = CurrentDeviceBounds;

    [self.viewaddSubview:contentPageView.view];

    

    [selffallInTransitionToView:contentPageView.viewwith:backImageViewanimationTime:0.5transContent:nilcompletion:^{

        [contentPageViewenterAnimationWhenAppear];

    }];

    

//    jisuanqiView=[[JiSuanQiViewController alloc]init];

//    jisuanqiView.view.frame=CurrentDeviceBounds;

//    [self.view addSubview:jisuanqiView.view];

//    

//    [jisuanqiView enterAnimationWhenAppear];

}

@end

 

转载于:https://www.cnblogs.com/alihaiseyao/p/3603811.html

 类似资料: