Iphone 如何使用滚动视图而不是滚动视图中的uibutton添加图像?

Iphone 如何使用滚动视图而不是滚动视图中的uibutton添加图像?,iphone,xcode,uiview,uiscrollview,uiimageview,Iphone,Xcode,Uiview,Uiscrollview,Uiimageview,在这段代码中,我想做一些更改,比如,我想在图像视图中创建图像,而不是按钮,在图像视图中使用带有放大和缩小事件的滚动视图。每个图像视图上有两个或三个按钮,这样我就可以在按钮上实现一些事件。你怎么知道的 - (void)loadView { [super loadView]; self.view.backgroundColor = [UIColor redColor]; UIScrollView *scroll = [[UIScrollView

在这段代码中,我想做一些更改,比如,我想在图像视图中创建图像,而不是按钮,在图像视图中使用带有放大和缩小事件的滚动视图。每个图像视图上有两个或三个按钮,这样我就可以在按钮上实现一些事件。你怎么知道的

- (void)loadView {
         [super loadView];
         self.view.backgroundColor = [UIColor redColor];

         UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,        self.view.frame.size.width, self.view.frame.size.height)];
         scroll.pagingEnabled = YES;

        NSInteger numberOfViews = 33;
        [btnMenu setTag:0 ];
        for (int i = 1; i < numberOfViews; i++) {
            CGFloat yOrigin = i * self.view.frame.size.width;
            UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
            //awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
            btnMenu = [UIButton buttonWithType:UIButtonTypeCustom];
            //NSData *data =UIImageJPEGRepresentation(, 1);
            [btnMenu setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"page-%d.jpg",i]] forState:UIControlStateNormal];

            CGRect frame = btnMenu.frame;
            frame.size.width=320;
            frame.size.height=460;
            frame.origin.x=0;
            frame.origin.y=0;
            btnMenu.frame=frame;

            [btnMenu setTag:i];
            btnMenu.alpha = 1;

            [btnMenu addTarget:self action:@selector(btnSelected:) forControlEvents:UIControlEventTouchUpInside];
            [awesomeView addSubview:btnMenu];

            [scroll addSubview:awesomeView];
            [awesomeView release];
         }
         scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews,   self.view.frame.size.height);
         [self.view addSubview:scroll];
         [scroll release];
}

-(IBAction)btnSelected:(id)sender{
    UIButton *button = (UIButton *)sender;
    int whichButton = button.tag;
    NSLog(@"Current TAG: %i", whichButton);
    if(whichButton==1)
    {
        first=[[FirstImage alloc]init];
        [self.navigationController pushViewController:first animated:YES];
    }

}
-(无效)加载视图{
[超级加载视图];
self.view.backgroundColor=[UIColor redColor];
UIScrollView*scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
scroll.paginEnabled=是;
NSInteger numberOfViews=33;
[btnMenu setTag:0];
对于(int i=1;i
您需要图像而不是按钮,对吗?然后试试这个:

    scroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    scroll.backgroundColor=[UIColor clearColor];
    scroll.pagingEnabled=YES;
    scroll.contentSize = CGSizeMake(320*33, 300);
    CGFloat x=0;
    for(int i=1;i<34;i++)
    {        
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(x+0, 0, 320, 460)];
        [image setImage:[UIImage imageNamed:[NSString stringWithFormat:@"page-%d.jpg",i]]];
        [scroll addSubview:image];
        [image release];
        x+=320;
    }
    [self.view addSubview:scroll];
    scroll.showsHorizontalScrollIndicator=NO;
    [scroll release];
scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0320460)];
scroll.backgroundColor=[UIColor clearColor];
scroll.PaginEnabled=是;
scroll.contentSize=CGSizeMake(320*33300);
cgx=0;

对于(int i=1;我仍然不太明白你在问什么。你的句子没有意义。我是说,在上面的代码中,我添加了带视图的uibutton。在这里,我想添加带有滚动启用功能的图像。作为旁注,请在你的帖子中使用正确的大小写。我正在键入的这句话是大写的。我正在键入的这句话是大写的't.如何应用放大和缩小功能?将UIPinchGestureRecognitizer应用于图像,以便可以使用UIPinchGestureRecognitizer代理进行缩放。