当前位置:编程学习 > wap >>

block 滑块导航条 关联

@property(nonatomic,retain)UIView *block;
 
-(void)btnClicked:(UIButton *)sender
{
     __block CGRect targetFrame = self.block.frame;
    BOOLdirectionRight=targetFrame.origin.x<sender.frame.origin.x;
    targetFrame.origin.x=sender.frame.origin.x+(directionRight?30:-30);
 
    [UIView animateWithDuration:0.1 animations:^{
        self.block.frame=targetFrame;
    }completion:^(BOOL finished){
        targetFrame.origin.x+=directionRight?-50:50;
        [UIView animateWithDuration:0.1 animations:^{
            self.block.frame=targetFrame;
        }completion:^(BOOL finished){
            targetFrame.origin.x+=directionRight?20:-20;
            [UIView animateWithDuration:0.1 animations:^{
                self.block.frame=targetFrame;
            }];
        }];
    }];
}
-(void)buildLayout{
   NSArray *arrbtn=@[@"主菜单",@"收藏",@"最近使用",@"更多。。。",];
 
    self.view.backgroundColor=[UIColor colorWithRed:241/255.0fgreen:200/255.0f blue:55/255.0f alpha:1.0f];
    
    for (int i=0; i<5; i++) {
        UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];
        //[btn setTitle:[NSString stringWithFormat:@"btn%d",i]forState:UIControlStateNormal];
        btn.frame=CGRectMake(64*i,CGRectGetHeight(self.view.bounds)-40, 64, 40); 
 
 
 [btn setTitle:[arrbtn objectAtIndex:i] forState:UIControlStateNormal];
        btn.layer.backgroundColor=[UIColor clearColor].CGColor;
        btn.layer.borderWidth=1.0f;
        [btn addTarget:self action:@selector(btnClicked:)forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
    UIView *blockBg=[[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetHeight(self.view.bounds)-60, 320, 20)];
    blockBg.backgroundColor=[UIColor clearColor];
    [self.view addSubview:blockBg];
    
    UIView *bgLayer=[[UIView alloc]initWithFrame:blockBg.frame];
    bgLayer.backgroundColor=[UIColor clearColor];
    bgLayer.layer.opacity=0.4f;
    [blockBg addSubview:bgLayer];
    
    self.block=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 64,20)];
    self.block.backgroundColor=[UIColor orangeColor];
    self.block.layer.opacity=1.0f;
    [blockBg addSubview:self.block];
    
    
}
 
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,