我有一个滚动视图和两个子视图,其中一个图像视图和一个按钮视图包含一些与图像视图有线条的热点。我想放大/缩小并相应地移动热点。我遇到的问题是我无法将热点保留在我想要的地方,也无法在这里找到解决方案。
这是我在 viewDidLoad 中的代码
- (void)viewDidLoad
{
[super viewDidLoad];
// set the tag for the image view
[imageView setTag:ZOOM_VIEW_TAG];
imageScrollView.delegate = self;
float sexy = [imageScrollView frame].size.height / [imageView frame].size.height;
initialZoom = sexy;
[imageScrollView setZoomScale:sexy animated:NO];
[imageScrollView setMinimumZoomScale:sexy];
[imageScrollView setContentInset:UIEdgeInsetsMake(-30, 0, 0, 0)];
scaleStart = imageScrollView.zoomScale;
buttonView = [[UIView alloc]init];
buttonView.frame = imageScrollView.frame;
[imageScrollView addSubview:buttonView];
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchDown];
[buttonView addSubview:button];
[button setTitle:@"Button x" forState:UIControlStateNormal];
button.frame = CGRectMake(200.0, 400.0, 520.0, 150.0);
imageView.center = self.view.center;
imageScrollView.maximumZoomScale = MAX_ZOOM_SCALE;
//setting an orientation notifier
UIDevice *device = [UIDevice currentDevice]; //Get the device object
[device beginGeneratingDeviceOrientationNotifications]; //Tell it to start monitoring the accelerometer for orientation
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //Get the notification centre for the app
[nc addObserver:self //Add yourself as an observer
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:device];
}
我正在尝试实现我的其余代码
- (void)scrollViewDidZoom:(UIScrollView *)aScrollView
使用 aScrollView.zoomScale 属性没有任何运气。
并将按钮视图移动到正确的位置。我遇到的问题是,当我放大(完全放大)时,缩放比例为 0.53454,而当我(完全)缩小时,我得到的值为 0.37261,为什么会发生这种情况,我不会再次获得第一个价值?
我怎么能做我想做的事?
当放大/缩小时,我想要谷歌地图之类的东西,并且地点保持在原位而不放大自己。