图片放大缩小的区域点击事件代码例子

比如我们有个中国地图,在北京这个区域放了一个button,当这张地图放大和缩小的时候,我们都能点击这个button触发北京里面的事件。
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    x = 1;
    y = 1;
 
    UIImage *image = [UIImage imageNamed:@"index_big.jpg"];
    imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(0, 0, 1024, 768);
    imageView.userInteractionEnabled = YES;
 
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
    scrollView.maximumZoomScale = 3.0;
    scrollView.minimumZoomScale = 1.0;
    scrollView.delegate = self;
    [self.view addSubview:scrollView];
    [self.view bringSubviewToFront:scrollView];
 
    [scrollView addSubview:imageView];
    [scrollView bringSubviewToFront:imageView];
}
 
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:YES];
    uaButton = [UIButton buttonWithType:UIButtonTypeCustom];
    uaButton.frame = CGRectMake(731*x, 235*y, 130, 60);
    [uaButton setTag:1];
    [uaButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:uaButton];
}
 
#pragma mark -
#pragma mark view zoom
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return imageView;
}
 
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
    NSLog(@"scrollViewDidEndZooming  width:%f, height:%f",imageView.frame.size.width, imageView.frame.size.height);
    x = imageView.frame.size.width/1024;
    y = imageView.frame.size.height/768;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值