我有一個UIScrollView
它有一個UIImageView
。我想在此imageView
上顯示引腳。當我將引腳添加爲ImageView
的子視圖時,除了縮放引腳上的縮放變換時,一切都非常棒。我不希望這種行爲,並希望我的針腳保持不變。UIScrollView ImageView頂部針腳
所以我選擇將引腳添加到位於ImageView頂部的另一個視圖,並且也是UIScrollView
的子視圖。這裏的想法,如果你會想象的是有一個圖層懸停在地圖上,不會縮放,但顯示在我繪製它們的地方。
如果ImageView
縮放,則添加到圖層視圖時的引腳不會進行縮放。然而,問題隨後變成了針腳的位置與原始原點x/y不匹配,因爲ImageView
已經進行了比例變換。
基本上這是一個帶有引腳的地方的自定義地圖。我正在嘗試讓引腳浮起來,而不是放大和縮小我的ImageView,但記住放大時發生的位置。
一些代碼:
scrollView = [[UIScrollView alloc] initWithFrame:viewRect];
scrollView.delegate = self;
scrollView.pagingEnabled = NO;
scrollView.scrollsToTop = NO;
[scrollView setBackgroundColor:[UIColor clearColor]];
scrollView.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView.bounces = YES;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
imageViewMap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
imageViewMap.userInteractionEnabled = YES;
viewRect = CGRectMake(0,0,imageViewMap.image.size.width,imageViewMap.image.size.height);
//viewRect = CGRectMake(0,0,2976,3928);
[scrollView addSubview:imageViewMap];
[scrollView setContentSize:CGSizeMake(viewRect.size.width, viewRect.size.height)];
iconsView = [[UIView alloc] initWithFrame:imageViewMap.frame];
[scrollView addSubview:iconsView];
代碼稍後添加引腳上的一些事件。
[iconsView addSubview:pinIcon];
我被困在試圖TP找出如何讓我的腳在地圖上懸停不動,當規模發生了。
這太棒了我有點生病。我有許多其他令人費解的方法可以做到這一點...非常簡單。我切換到這個,它很好。 – malaki1974 2013-07-03 18:42:20