【问题标题】:Zoom with Zoomed Buttons on a UIImageView使用 UIImageView 上的缩放按钮进行缩放
【发布时间】:2012-06-04 15:29:45
【问题描述】:

我在 UIImageView 中有一张地图的平面图像,我的工作是向一些预定义的“热点”添加清晰的按钮,这些“热点”代表地图上感兴趣的位置。但是,考虑到 iPhone 上图像的大小,他们定义的热点非常靠近,很难触摸/点击。

有没有办法放大图像,让这些按钮放大,以便更容易按下?

【问题讨论】:

    标签: objective-c ios


    【解决方案1】:

    是的,在滚动视图中添加图像视图, 使用此代码

    - (void)viewDidLoad {
        [super viewDidLoad];
        UIImageView *imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage"]];
        self.imageView = imageview;
        [imageview release];
    
        scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
        scrollView.maximumZoomScale = 4.0;
        scrollView.minimumZoomScale = 0.75;
        scrollView.clipsToBounds = YES;
        scrollView.delegate = self;
        [scrollView addSubview:imageView];
    }
    
    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
        return imageView;
    }
    

    在 .h 文件中你会拥有

    @property (nonatomic, retain) UIScrollView *scrollView;
    @property (nonatomic, retain) UIImageView *imageView;
    

    有关更多信息,请查看 StackOverFlow 以了解如何添加以使用 UIScrollView 比如Adding UIImageViews to UIScrollView

    【讨论】:

    • 是的,这是有道理的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 1970-01-01
    • 2020-10-01
    • 2012-05-27
    • 2011-02-05
    相关资源
    最近更新 更多