用户个人界面简单UI及手势动画设计

来源:互联网 发布:java新技术框架 编辑:程序博客网 时间:2024/05/29 09:36
<pre name="code" class="objc">//    创建背景图    UIImageView *backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 20, 320, self.view.frame.size.height -20)];    [backImageView setImage:[UIImage imageNamed:@"111111.jpeg"]];    [self.view addSubview:backImageView];    [backImageView release];    _showInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 250)];    [self.view addSubview:_showInfoView];    [_showInfoView release];

     //可拖动块图    _imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, -10, 320, 240)];    [_imageview setImage:[UIImage imageNamed:@"backImage2"]];    [_showInfoView addSubview:_imageview];    [_imageview release];    <pre name="code" class="objc"> <pre name="code" class="objc">    //用户头像    UIButton * userimageButton = [[UIButton alloc]initWithFrame:CGRectMake(130, 60, 70, 70)];    userimageButton.layer.cornerRadius = 35;    userimageButton.layer.masksToBounds = YES;    [userimageButton setImage:[UIImage imageNamed:@"lala.png"] forState:UIControlStateNormal];    [_imageview addSubview:userimageButton];    [userimageButton release];
 //随便写    UIButton * messagebutton = [[UIButton alloc] initWithFrame:CGRectMake(90, 150, 60, 20)];    [messagebutton setImage:[UIImage imageNamed:@"information.png"] forState:UIControlStateNormal];    [messagebutton setBackgroundColor:[UIColor whiteColor]];    [messagebutton setTitle:@"随便写" forState:UIControlStateNormal];    [messagebutton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];    messagebutton.titleLabel.font= [UIFont systemFontOfSize:10.0];    //    改变字体位置 上左下右    [messagebutton setTitleEdgeInsets:UIEdgeInsetsMake(0, 9, 0, 0)];    //    //    改变图片位置    [messagebutton setImageEdgeInsets:UIEdgeInsetsMake(0, 3, 3, 45)];    messagebutton.layer.cornerRadius = 8;    messagebutton.layer.masksToBounds = YES;        [_imageview addSubview: messagebutton];    [messagebutton release];


//   随便扯    UIButton * friendsbutton = [[UIButton alloc] initWithFrame:CGRectMake(170, 150, 60, 20)];    [friendsbutton setImage:[UIImage imageNamed:@"friends.png"] forState:UIControlStateNormal];    [friendsbutton setBackgroundColor:[UIColor whiteColor]];    [friendsbutton setTitle:@"随便扯" forState:UIControlStateNormal];    [friendsbutton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];    friendsbutton.titleLabel.font= [UIFont systemFontOfSize:10.0];    //    改变字体位置 上左下右    [friendsbutton setTitleEdgeInsets:UIEdgeInsetsMake(0, 9, 0, 0)];    //    //    改变图片位置    [friendsbutton setImageEdgeInsets:UIEdgeInsetsMake(0, 3, 0, 45)];    friendsbutton.layer.cornerRadius = 8;    friendsbutton.layer.masksToBounds = YES;        [_imageview addSubview: friendsbutton];    [friendsbutton release];

  //    遮挡条    _closeview = [[UIView alloc] initWithFrame:CGRectMake(0, 190, 320, 50)];    [_closeview setBackgroundColor:[UIColor whiteColor]];    _imageview.userInteractionEnabled = YES;    [_closeview setUserInteractionEnabled:YES];    [_imageview addSubview:_closeview];    [_closeview release];    //    提示    UIButton * kmbutton = [[UIButton alloc] initWithFrame:CGRectMake(100, 5, 150, 30)];    [kmbutton setBackgroundColor:[UIColor lightGrayColor]];   [kmbutton setTitle:@"^_^ 拖这里~" forState:UIControlStateNormal];   [_closeview addSubview:kmbutton];   [kmbutton release];    //   添加手势    [self gesture];}

-(void)gesture{        //        拖拽手势        UIPanGestureRecognizer * pan1 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pangesture:)];    [_closeview addGestureRecognizer:pan1];    [pan1 release];    }

////拖拽手势的响应事件-(void)pangesture:(UIPanGestureRecognizer*)gesture{    CGPoint point = [gesture translationInView:_clearview];    //hiddenView向下    if (point.y>0&&_showInfoView.frame.origin.y>=0&&_hiddenview.frame.origin.y<195) {        [_hiddenview setFrame:CGRectMake(_hiddenview.frame.origin.x, _hiddenview.frame.origin.y+point.y, _hiddenview.frame.size.width, _hiddenview.frame.size.height)];    }    //hiddenview向上走    if (point.y<0&&_hiddenview.frame.origin.y>0) {        [_hiddenview setFrame:CGRectMake(_hiddenview.frame.origin.x, _hiddenview.frame.origin.y+point.y, _hiddenview.frame.size.width, _hiddenview.frame.size.height)];    }    //showView向上跑    if (point.y<0&&_hiddenview.frame.origin.y <=0) {                        if (_showInfoView.frame.origin.y  <= -(SHOWVIEWHEIGHT-70)/2) {            [UIView animateWithDuration:0.4 animations:^{                [_showInfoView setFrame:CGRectMake(0, 70-SHOWVIEWHEIGHT, 320, SHOWVIEWHEIGHT)];            } completion:nil];        }else{            [_showInfoView setFrame:CGRectMake(_showInfoView.frame.origin.x, _showInfoView.frame.origin.y+point.y, _showInfoView.frame.size.width, _showInfoView.frame.size.height)];                        if (_clearview.frame.size.height<self.view.frame.size.height) {                [_clearview setFrame:CGRectMake(0, _clearview.frame.origin.y+point.y, 320, _clearview.frame.size.height-point.y)];            }            else{                [_clearview setFrame:CGRectZero];                            }                    }                            }

//    //showView消失后,向下拖拽,显示showView    if (point.y>0&&_showInfoView.frame.origin.y<0) {                                if (_showInfoView.frame.origin.y>=-(SHOWVIEWHEIGHT-70)/2) {            [UIView animateWithDuration:0.4 animations:^{                                [_showInfoView setFrame:CGRectMake(0, 0, 320, SHOWVIEWHEIGHT)];                            } completion:nil];        }else {            [_showInfoView setFrame:CGRectMake(_showInfoView.frame.origin.x, _showInfoView.frame.origin.y+point.y, _showInfoView.frame.size.width, _showInfoView.frame.size.height)];        }                    }                    NSLog(@"%f    隐藏的  orign.y",  point.y);    //    每次拖拽前还原    [gesture setTranslation:CGPointMake(0, 0) inView:_clearview];    }


                                             
0 0
原创粉丝点击