自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS實(shí)現(xiàn)類似魔獸小地圖功能

移動(dòng)開(kāi)發(fā) iOS
比如你有一個(gè)可以放大縮小的scrollView。會(huì)在里面進(jìn)行一些放大縮小,點(diǎn)擊里面的按鈕呀,等操作。這個(gè)小地圖控件。就會(huì)和你的大scrollView同步。并有縮略圖和你當(dāng)前視口的位置。就像游戲里那樣。

寫(xiě)了一個(gè)類似魔獸小地圖功能的控件。

比如你有一個(gè)可以放大縮小的scrollView。會(huì)在里面進(jìn)行一些放大縮小,點(diǎn)擊里面的按鈕呀,等操作。

這個(gè)小地圖控件。就會(huì)和你的大scrollView同步。并有縮略圖和你當(dāng)前視口的位置。就像游戲里那樣。

看圖。

SmallMapView.h

  1. // 
  2. //  SmallMapView.h 
  3. //  littleMapView 
  4. // 
  5. //  Created by fuqiang on 13-7-2. 
  6. //  Copyright (c) 2013年 fuqiang. All rights reserved. 
  7. // 
  8.  
  9. #import <UIKit/UIKit.h> 
  10. #import <QuartzCore/QuartzCore.h> 
  11.  
  12. @interface SmallMapView : UIView 
  13.  
  14. //縮放比例 
  15. @property (nonatomic,assign,readonly)float scaling; 
  16.  
  17. //標(biāo)示窗口位置的浮動(dòng)矩形 
  18. @property (nonatomic,retain,readonly)CALayer *rectangleLayer; 
  19.  
  20. //內(nèi)容 
  21. @property (nonatomic,retain,readonly)CALayer *contentLayer; 
  22.  
  23. //被模擬的UIScrollView 
  24. @property (nonatomic,retain,readonly)UIScrollView *scrollView; 
  25.  
  26. //init 
  27. - (id)initWithUIScrollView:(UIScrollView *)scrollView frame:(CGRect)frame; 
  28.  
  29. //在UIScrollView的scrollViewDidScroll委托方法中調(diào)用 
  30. - (void)scrollViewDidScroll:(UIScrollView *)scrollView; 
  31.  
  32. //重繪View內(nèi)容(需要注意。如果在調(diào)用reloadSmallMapView 方法的時(shí)候,需要更新的內(nèi)容內(nèi)有動(dòng)畫(huà)。如按鈕變色等) 
  33. //請(qǐng)用[self performSelector:@selector(reloadSmallMapView:) withObject:nil afterDelay:0.2]; 
  34. - (void)reloadSmallMapView; 
  35. @end 

SmallMapView.m

  1. // 
  2. //  SmallMapView.m 
  3. //  littleMapView 
  4. // 
  5. //  Created by fuqiang on 13-7-2. 
  6. //  Copyright (c) 2013年 fuqiang. All rights reserved. 
  7. // 
  8.  
  9. #import "SmallMapView.h" 
  10.  
  11. @implementation SmallMapView 
  12.  
  13. - (id)initWithUIScrollView:(UIScrollView *)scrollView frame:(CGRect)frame 
  14.     self = [super init]; 
  15.     if (self) { 
  16.         _scrollView = scrollView; 
  17.          
  18.         //設(shè)置縮略圖View尺寸 
  19.         [self setFrame:frame]; 
  20.          
  21.         //設(shè)置縮略圖縮放比例 
  22.         [self setScaling:_scrollView]; 
  23.          
  24.         //設(shè)置羅略圖內(nèi)容 
  25.         _contentLayer = [self drawContentView:_scrollView frame:frame]; 
  26.         [self.layer addSublayer:_contentLayer]; 
  27.          
  28.         //初始化縮略移動(dòng)視口 
  29.         _rectangleLayer = [[CALayer alloc] init]; 
  30.         _rectangleLayer.opacity = 0.5; 
  31.         _rectangleLayer.shadowOffset = CGSizeMake(0, 3); 
  32.         _rectangleLayer.shadowRadius = 5.0; 
  33.         _rectangleLayer.shadowColor = [UIColor blackColor].CGColor; 
  34.         _rectangleLayer.shadowOpacity = 0.8; 
  35.         _rectangleLayer.backgroundColor = [UIColor whiteColor].CGColor; 
  36.         _rectangleLayer.frame = CGRectMake(0, 0, scrollView.frame.size.width * _scaling, scrollView.frame.size.height * _scaling); 
  37.         [self.layer addSublayer:_rectangleLayer]; 
  38.     } 
  39.     return self; 
  40.  
  41. - (void)dealloc 
  42.     [_rectangleLayer release]; 
  43.     [super dealloc]; 
  44.  
  45. //------ 
  46. - (void)scrollViewDidScroll:(UIScrollView *)scrollView 
  47.     [self setScaling:scrollView]; 
  48.     float x = scrollView.contentOffset.x; 
  49.     float y = scrollView.contentOffset.y; 
  50.     float h = scrollView.frame.size.height; 
  51.     float w = scrollView.frame.size.width; 
  52.     [self.rectangleLayer setFrame:CGRectMake(x * _scaling, y * _scaling, h * self.scaling, w * self.scaling)]; 
  53.  
  54. //重繪View內(nèi)容 
  55. - (void)reloadSmallMapView 
  56.     [_contentLayer removeFromSuperlayer]; 
  57.     _contentLayer = [self drawContentView:_scrollView frame:self.frame]; 
  58.     [self.layer insertSublayer:_contentLayer atIndex:0]; 
  59.  
  60. //設(shè)置縮略圖縮放比例 
  61. - (void)setScaling:(UIScrollView *)scrollView 
  62.     _scaling = self.frame.size.height / scrollView.contentSize.height; 
  63.  
  64. //復(fù)制UIScrollView中內(nèi)容 
  65. - (CALayer *)drawContentView:(UIScrollView *)scrollView frame:(CGRect)frame 
  66.     [self setScaling:scrollView]; 
  67.     CALayer *layer = [[CALayer alloc] init]; 
  68.     layer.frame = frame; 
  69.     for (UIView *view in scrollView.subviews) 
  70.     { 
  71.         UIGraphicsBeginImageContext(view.bounds.size); 
  72.         [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
  73.         UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
  74.         UIGraphicsEndImageContext(); 
  75.          
  76.         CALayer *copyLayer = [CALayer layer]; 
  77.         copyLayer.contents = (id)image.CGImage; 
  78.         float x = view.frame.origin.x; 
  79.         float y = view.frame.origin.y; 
  80.         float h = view.frame.size.height; 
  81.         float w = view.frame.size.width; 
  82.         copyLayer.frame = CGRectMake(x * _scaling,y *_scaling,w * _scaling,h * _scaling); 
  83.         [layer addSublayer:copyLayer]; 
  84.     } 
  85.     return [layer autorelease]; 
  86. @end 

 

責(zé)任編輯:閆佳明 來(lái)源: cnblogs
相關(guān)推薦

2011-11-30 15:51:57

2017-09-01 15:42:00

MySQLOracledblink功能

2011-07-07 16:53:56

iOS 條形碼掃描

2021-08-04 16:40:59

Google地圖實(shí)時(shí)分享位置工具

2009-05-04 09:09:17

木馬安全漏洞

2009-03-19 00:15:17

2015-01-15 16:45:05

iOS源碼自定義畫(huà)圖

2017-04-01 10:49:31

miui小米MIUI

2013-06-28 10:37:57

Google EartiOS

2020-06-10 14:42:30

AndroidiOSCOVID-19

2013-07-29 04:46:48

iOS開(kāi)發(fā)iOS開(kāi)發(fā)學(xué)習(xí)iOS小知識(shí)

2021-07-06 12:06:40

React

2011-05-07 09:21:47

必應(yīng)地圖iOS谷歌地圖

2009-05-04 18:02:24

微軟MSN地圖共享

2023-11-30 08:06:43

Springboot地理位置

2016-04-20 09:47:40

MapBoxAndroid地圖

2012-05-13 14:15:49

2012-05-16 18:21:27

2009-07-06 09:17:51

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)