2010-04-28 5 views
0

저는 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

답변

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 

}는 SCR을 만드는 동안

망가 인터페이스 빌더

에있는 ScrollView를 연결하는 것을 잊지 IB의 ollview는 ur ur scrollView 높이가 네비게이션 bar.so의 기본값 인 44.so가 멋지게 보이는지 확인합니다.

in viewDidLoad call 

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

OUTPUT

enter image description here

관련 문제