【问题标题】:how to have a sliding menu on the top of the page如何在页面顶部有一个滑动菜单
【发布时间】:2011-02-13 11:38:38
【问题描述】:

我是 iphone 编程新手。我在 iTunes 上浏览不同的应用程序。找到了这个很棒的菜单。你们能帮我理解在技术上要做什么来实现这个菜单吗?

用户可以从左向右滑动此菜单,反之亦然,而不会影响底部的视图。如何做到这一点?提前致谢

alt text http://a1.phobos.apple.com/us/r1000/039/Purple/ed/2d/d7/mzl.uawcjxjf.320x480-75.jpg

alt text http://a1.phobos.apple.com/us/r1000/019/Purple/54/e1/08/mzl.usfrcvkh.320x480-75.jpg

【问题讨论】:

    标签: iphone iphone-sdk-3.0 uiview


    【解决方案1】:

    .h

    IBOutlet UIScrollView *scrollView;
    
    @property ( nonatomic , retain )  IBOutlet UIScrollView *scrollView;
    
    -(void)AppleVijayAtFacebookDotCom:(id)sender;
    
    -(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons;
    

    .m

    @synthesize scrollView;
    
    
    
    -(void)AppleVijayAtFacebookDotCom:(id)sender{
    
    
        NSLog(@"AppleVijayAtFacebookDotCom called");
    
    
        UIButton *button=(UIButton *)sender;
    
    
        if (button.tag == 0) {
    
            NSLog(@"hey have clicked first button, this is my tag : %i \n\n",button.tag);
        }
        else if (button.tag == 1) {
    
            NSLog(@"hey have clicked second button, this is my tag : %i \n\n",button.tag);
    
        }
        // ......like this
    
        NSLog(@"button clicked is : %iBut \n\n",button.tag);
    
    
    
    }       
    
    
    
    -(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons{
    
    for (int i = 0; i < totalNoOfButtons; i++) {
    
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
        [button addTarget:self action:@selector(AppleVijayAtFacebookDotCom:) forControlEvents:UIControlEventTouchUpInside];
    
            //[button1 setImage:[UIImage imageNamed:@"Button.png"] forState:UIControlStateNormal];//with image
    
            //OR
    
        [button setTitle:[NSString stringWithFormat:@"%iBut",i] forState:UIControlStateNormal];//with title
    
        button.frame = CGRectMake(i*(offset+buttonSize.width), 8.0, buttonSize.width, buttonSize.height);
    
        button.clipsToBounds = YES;
    
        button.showsTouchWhenHighlighted=YES;
    
        button.layer.cornerRadius = 10;//half of the width
    
        button.layer.borderColor=[UIColor redColor].CGColor;
    
        button.layer.backgroundColor=[UIColor blackColor].CGColor;
    
        button.layer.borderWidth=2.0f;
    
        button.tag=i;
    
        [self.scrollView addSubview:button];
    
    }
    
    self.scrollView.contentSize=CGSizeMake((buttonSize.width + offset) * totalNoOfButtons, buttonSize.height);
    
        //self.navigationItem.titleView=self.scrollView;//if u have navigationcontroller then enable this line
    

    }

    不要忘记在界面生成器中连接scrollView

    在 IB 中创建滚动视图时,确保您的滚动视图高度为 44。这是导航栏的默认值。所以它看起来不错。

    in viewDidLoad call 
    
    [self createMenuWithButtonSize:CGSizeMake(70.0, 30.0) withOffset:20.0f noOfButtons:30];
    

    输出

    【讨论】:

      【解决方案2】:

      这个例子帮助了我。 http://blog.sallarp.com/iphone-sliding-menu/

      【讨论】:

      • 答案中的链接已失效 - "404 Not Found".
      猜你喜欢
      • 2012-05-26
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多