je deux UIView
un sur l'autre, où le premier a COULEUR ROUGE comme backgroundColor
, et la partie supérieure est blanche comme backgroundColor
, lorsque des touches utilisateur et les nuances de la UIVIEW
supérieure du bas UIView
a être visible .. est-ce possible ici ... ??fonction d'effacement dans UIView sur UITouch
Répondre
Oui c'est possible, je l'ai aussi fait dans mon projet. Jetez un oeil à cette link
espère que cela vous aide à ce que vous voulez faire ;-)
grâce shah .... upvoted .. –
je code avec classe pour votre cette exigence .. juste essayer de comprendre le flux
Créer un UIView classe comme ci-dessous ...
voir ci-dessous fichier 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
et aussi TouchView.m
fil e comme ci-dessous ..
// 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
juste ajouter ce point de vue comme une sous-vue de votre MainView comme ci-dessous ...
d'abord ajouter la classe dans le fichier .h ..
@class TouchView;
puis créer objet comme ci-dessous dans .h
fichier ..
TouchView *viewScratch;
et dans le fichier .m
ajoutez ce code
- (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];
}
@HarishSaran voir ce lien aussi pour ce mec http://www.supersuraccoon-cocos2d.com/2011/06/05/scratch-off-demo/ J'espère que cela vous aidera :) –
- 1. Faire pivoter UIView en utilisant UITouch
- 2. UITouch sur chevauchement UIViews
- 3. Problème tactile multiple en utilisant UITouch/UIView dans l'iphone
- 4. Minutage d'une instance UITouch
- 5. UIButton se bloque sur l'événement uitouch
- 6. Comment gérer les événements UITouch sur UIScrollView?
- 7. Désactiver UIView sur TouchesMoved
- 8. déplacement UITextField dans UIView
- 9. CGAffineTransformMakeTranslation suivez UITouch Emplacement
- 10. Désactiver toucesMoved sur UIView
- 11. Uitouch déplacé animation
- 12. uiview touch move obtenir le point d'ancrage sur uiview
- 13. objet UITouch se comporter bizarrement
- 14. UITouch équivalent pour Mac
- 15. touchesBegan seulement dans UIView spécifique
- 16. UITouch - événement ne répond pas
- 17. Modification de l'emplacement d'entrée UITouch
- 18. UIView dans les UIView
- 19. Simulation UITouch dans xCode 4.5 par programme (UISpec)
- 20. UIView dans UIView issue
- 21. IOS, Xcode: capture événement UITouch terminé
- 22. touchesMoved détection UIView
- 23. UIView Animation sur plusieurs UIImageViews dans ARC
- 24. Mouvement UIView
- 25. Je ne peux pas détecter UItouch
- 26. appeler des méthodes de uitableview de UITouch
- 27. Peinture transparente sur UIView
- 28. iOS CGAffineTransform sur UIView
- 29. Transitions UIView sur iPad?
- 30. UIView Animation Annuler
reformulons la question un peu .. on ne sait pas ce que vous voulez - ajouter un peu de code avec ce que vous avez essayé et ainsi de suite –