我有兩個UIView
一個在另一個之上,其中,所述第一個具有紅色作爲backgroundColor
,並且上一個具有白色如backgroundColor
,當用戶觸摸和色調上UIVIEW
下UIView
具有是可見的..有可能在這裏...?擦除功能上UITouch
-1
A
回答
1
0
我有類代碼爲你的這個要求是什麼..只是試着去了解流動
創建一個UIView類像波紋管......
看到TouchView.h
文件波紋管..
//
// TouchView.h
//
// Created by Paras Joshi on 23/08/12..
//
#import <UIKit/UIKit.h>
@interface TouchView : UIView {
// array of all the touch locations
NSMutableArray *points;
// image to mask on user gesture
UIImage *maskImage;
}
@property (nonatomic, retain) UIImage *maskImage;
@property (nonatomic, retain) NSMutableArray *points;
-(void)drawPic:(UIImage *)thisPic;
@end
,也TouchView.m
FIL Ë像波紋管..
// TouchView.m
//
// Created by Paras Joshi on 23/08/12..
#import "TouchView.h"
// Define method POINT to return the CGPoint value of the object at self.points[index]
#define POINT(index) [[self.points objectAtIndex:index] CGPointValue];
@interface TouchView (PrivateMethods)
-(void)clipImage;
@end
@implementation TouchView
@synthesize points,maskImage;
// mask will be a sphere of maskWidth X maskHeight
float maskWidth = 30.0f;
float maskHeight = 30.0f;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
self.backgroundColor = [UIColor clearColor];
self.points = [NSMutableArray array];
// set the 'maskImage'
maskImage = [[UIImage alloc]init];
// maskImage = [UIImage imageNamed:@"house1.jpeg"];
// listen for 'reset' notification event
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(reset:)
// name:ResetNotification
// object:nil];
}
return self;
}
-(void)drawPic:(UIImage *)thisPic {
maskImage = thisPic;
[maskImage retain];
[self setNeedsDisplay];
}
-(void)reset:(NSNotification *)notification{
[self.points removeAllObjects];
[self setNeedsDisplay];
}
-(void)drawRect:(CGRect)rect{
// break if there are no points to mask
if (!self.points || self.points.count < 2) return;
// mask the image
[self clipImage];
}
// clipImage handles creating and adding a path of masks (ellipses), to our drawing context (display) based on gesture input
- (void) clipImage{
// grab a reference to the image we're going to mask
UIImage *image = maskImage;
// determine the extents of the image so that we do not
// do unnecessary drawing ouside the image bounds
// CGRect bounds = CGRectMake(0.0f, 0.0f, maskImage.size.width, maskImage.size.height);
CGRect bounds = CGRectMake(0.0f, 0.0f, 1024, 694);
// get the graphics context and init a path to draw our mask to
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
// add ellipses to every CGPoint in self.points
for(int i = 0; i < self.points.count - 1; i++){
// get the CGPoint value stored in self.points[i]
CGPoint pt = POINT(i);
// add the ellipse at that point
CGPathAddEllipseInRect(path, NULL, CGRectMake(pt.x - (maskWidth/2), pt.y - (maskHeight/2), maskWidth, maskHeight));
}
// add the path of ellipses to our drawing context
CGContextAddPath(context, path);
// clip the Core Graphics drawing context to our display
CGContextClip(context);
// now add the image to our display (it will only appear wherever the CGPoints of self.points are located)
[image drawInRect:bounds];
// finalize drawing
CGContextClosePath(context);
}
- (void)dealloc {
points = nil;
// remove event listener
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
#pragma mark -
#pragma mark Gesture Methods
-(BOOL) isMultipleTouchEnabled{ return NO; };
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// get the location of the touch
CGPoint pt = [[touches anyObject] locationInView:self];
// puch the touch location (pt) onto our array of points
[self.points addObject:[NSValue valueWithCGPoint:pt]];
// update display by calling it's 'drawRect' method
[self setNeedsDisplay];
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
// get the location of the touch
CGPoint pt = [[touches anyObject] locationInView:self];
// puch the touch location (pt) onto our array of points
[self.points addObject:[NSValue valueWithCGPoint:pt]];
// update display by calling it's 'drawRect' method
[self setNeedsDisplay];
}
@end
只需添加這種觀點爲您MAINVIEW像波紋管的子視圖...
先在.h文件中添加類..
@class TouchView;
,然後創建對象像.h
文件波紋管..
TouchView *viewScratch;
和.m
文件中添加以下代碼
- (void)viewDidLoad
{
viewScratch = [[TouchView alloc]initWithFrame:CGRectMake(0, 0, 1024, 694)];// set frame which you want...
[viewScratch clipsToBounds];
[viewScratch drawPic:[UIImage imageNamed:@"yourImageName"]];
[self.view addSubview:viewScratch];
}
+1
@HarishSaran看到這個鏈接也添加一些代碼那傢伙http://www.supersuraccoon-cocos2d.com/2011/06/05/scratch-off-demo/我希望這可以幫助你:) –
相關問題
- 1. 擦除功能塗料
- 2. QString字符擦除功能
- 3. jQuery/JS不刪除HTML上的JS功能擦除?
- 4. 擦除亮點JavaScript getSelection功能
- 5. 幫助C++清單擦除功能
- 6. OpenLayers eraseFeatures不會擦除地圖屏幕上的功能
- 7. 矢量擦除功能刪除錯誤的對象
- 8. 具有Waveform.js和擦除功能的Soundcloud自定義播放器
- 9. 如何實現散列表的擦除功能?
- 10. 幫助js功能/提醒擦除表單輸入
- 11. 熊貓應用的功能擦除數據
- 12. C++地圖擦除功能無法正確使用迭代器
- 13. 錯誤模板「查找和擦除」功能
- 14. 擦除或擦除LDAP記錄:如何?
- 15. 如何使用擦除功能通過索引擦除std :: vector <>中的多個元素?
- 16. 刪除功能並上傳
- 17. 奇怪擦除
- 18. flash.display.Graphics擦除
- 19. 擦除價值
- 20. 擦除值
- 21. 擦除元素
- 22. 通過擦除
- 23. 擦除詳細?
- 24. Kdtree C++擦除並插入低性能
- 25. 如何在畫布上擦除位圖時撤消擦除操作?
- 26. 如何使用sketch.min.js擦除點擊擦除按鈕上的畫布?
- 27. 擦除實際手機上的數據
- 28. 從平面上擦除紋理
- 29. 在線上擦除多個條目
- 30. Pygame擦除背景上的圖像
重新制定的問題有點..目前尚不清楚你想要的東西 - 也與你嘗試過什麼等等 –