UISwipeGestureRecognizer detecting swiped object - ios

I want to call a method when a UItextView is being slided on, and determine its tag. I was using this code:
-(IBAction)donecomment:(id)sender{
UISwipeGestureRecognizer *myLongPressRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(holdpress:)];
[textname addGestureRecognizer:myLongPressRecognizer];
textname.editable = NO;
textname.userInteractionEnabled = YES;
CGRect frame = textname.frame;
frame.size.height = textname.contentSize.height;
textname.frame = frame;
heightInteger = heightInteger + textname.contentSize.height + 6;
[textnameArray addObject:textname];
addComment.hidden = NO;
doneComment.hidden = YES;
cancelComment.hidden = YES;
}
-(void)holdpress:(id)sender{
UITextView *txtChoosen = (UITextView*) sender;
for (UITextView* txt in textnameArray) {
if (txt.tag == txtChoosen.tag) {
txt.layer.borderWidth = 5.0f;
txt.layer.borderColor = [[UIColor whiteColor] CGColor];
}else{
txt.layer.borderWidth = 0.0f;
txt.layer.borderColor = [[UIColor whiteColor] CGColor];
}}
...I get this error: reason: '-[PhotoViewController holdpress]: unrecognized selector sent to instance 0x22c1a000'
I think I can solve it using:
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
...but using htis means removing the sender. What can I do?

The error is complaining about a method named holdpress. In the code you posted you have a method named holdpress:. Note the difference - the method has a colon, the error method doesn't.
Also in the code you posted you setup the gesture recognizer to use the selector for holdpress:. This properly matches the method you actually have. That is correct.
Since the error is about holdpress and not holdpress:, you must have some other code that tries to use the holdpress selector instead of holdpress:.
Is the posted code from PhotoViewController?
Search your code for calls to holdpress (not holdpress:).

Final solution:
-(IBAction)donecomment:(id)sender{
UISwipeGestureRecognizer *myLongPressRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(leftSwipe:)];
//[myLongPressRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[textname addGestureRecognizer:myLongPressRecognizer];
textname.editable = NO;
textname.userInteractionEnabled = YES;
CGRect frame = textname.frame;
frame.size.height = textname.contentSize.height;
textname.frame = frame;
heightInteger = heightInteger + textname.contentSize.height + 6;
[textnameArray addObject:textname];
addComment.hidden = NO;
doneComment.hidden = YES;
cancelComment.hidden = YES;
}
- (void)leftSwipe:(UISwipeGestureRecognizer *)recognizer {
id sender;
UITextView *txtChoosen = (UITextView*) sender;
for (UITextView* txt in textnameArray) {
if (txt.tag == txtChoosen.tag) {
txt.layer.borderWidth = 5.0f;
txt.layer.borderColor = [[UIColor whiteColor] CGColor];
}else{
txt.layer.borderWidth = 0.0f;
txt.layer.borderColor = [[UIColor whiteColor] CGColor];
}}

Related

How can I remove the shadow of the confirm button when deleting in a table view?

How can I remove the shadow of the confirm button when deleting in a table view?
First, simply open the storyboard, click the button once to choose it and then set the shadow color to Default by clicking on the blue arrows:
The, try the following programmatically in the override func ViewDidLoad():
self.buttonOutlet.layer.shadowColor = UIColor.white.cgColor
self.buttonOutlet.layer.shadowOffset = CGSize(width: 0, height: 0)
self.buttonOutlet.layer.shadowRadius = 0
self.buttonOutlet.layer.shadowOpacity = 0
Replace buttonOutlet with the actual name of the button's outlet.
Let me know if that helped :)
I did resolve this ,We can custom to this button.
Handle on TableViewCell.
-(void)layoutIfNeeded {
[super layoutIfNeeded];
if ([self.subviews count] >= 4){
for(UIView* subView in self.subviews){
//DDLogDebug(#"JARED: subView %#",[subView class]);
if([NSStringFromClass([subView class]) isEqualToString:#"UITableViewCellEditControl"]){
for(UIView * subView2 in subView.subviews){
if ([subView2 isKindOfClass: [UIImageView class]] && subView2.frame.origin.y == 20) {
subView2.layer.shadowRadius = 11;
subView2.layer.shadowColor = [UIColor whiteColor].CGColor;
subView2.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
subView2.layer.shadowOpacity = 0.1;
subView2.layer.cornerRadius = 11;
subView2.layer.masksToBounds = NO;
subView2.layer.backgroundColor = [UIColor whiteColor].CGColor;
subView2.layer.contents = (id)[UIImage imageNamed:#"confirmDetele"].CGImage;
}
if ([subView2 isKindOfClass: [UIImageView class]] && subView2.frame.origin.y == 22) {
subView2.layer.contents = nil;
subView2.layer.shadowRadius = 11;
subView2.layer.shadowColor = [UIColor whiteColor].CGColor;
subView2.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
subView2.layer.shadowOpacity = 0.1;
subView2.layer.cornerRadius = 11;
subView2.layer.masksToBounds = NO;
subView2.layer.backgroundColor = [UIColor whiteColor].CGColor;
}
}
}
}
}
}

Cocos2D v3 CCTableView not scrolling

I am trying to use a CCTableView in my game. You should be able to scroll through a list of names. I am able to click on a cell and log the which cell was clicked. However when I try to scroll there is no movement.
#interface WSMPlayerCandidateSubMenu(){
CCNodeColor *_candidateSubMenuSprite;
}
#implementation WSMPlayerCandidateSubMenu
- (void)onEnter{
[super onEnter];
CGSize winSize = [[CCDirector sharedDirector] viewSize];
_candidateSubMenuSprite.color = [CCColor whiteColor];
_candidateSubMenuSprite.userInteractionEnabled = NO;
self.candidateArray = [[WSMGameManager sharedManager] returnCompany].candidates;
CCTableView *tblScores = [CCTableView node];
tblScores.contentSize = CGSizeMake(1.0,0.8);
tblScores.anchorPoint = ccp(0.5f,0.375f);
tblScores.positionType = CCPositionTypeNormalized;
tblScores.position = _candidateSubMenuSprite.position;
tblScores.userInteractionEnabled = YES;
tblScores.dataSource = self;
tblScores.verticalScrollEnabled = YES;
tblScores.block = ^(CCTableView *table){
NSLog(#"Cell %ld", (long)table.selectedRow);
};
[_candidateSubMenuSprite addChild:tblScores];
}
-(CCTableViewCell*)tableView:(CCTableView *)tableView nodeForRowAtIndex:(NSUInteger)index{
CCTableViewCell* cell = [CCTableViewCell node];
cell.contentSizeType = CCSizeTypeMake(CCSizeUnitNormalized, CCSizeUnitPoints);
cell.contentSize = CGSizeMake(1, 40);
// Color every other row differently
CCNodeColor* bg = [CCNodeColor nodeWithColor:[CCColor colorWithRed:52/255.f green:73/255.f blue:94/255.f]];
bg.userInteractionEnabled = NO;
bg.contentSizeType = CCSizeTypeNormalized;
bg.contentSize = CGSizeMake(1, 1);
[cell addChild:bg];
WSMEmployee *candidate = (WSMEmployee*)[self.candidateArray objectAtIndex:index];
CCLabelTTF *lblCompanyName = [CCLabelTTF labelWithString:candidate.name fontName:#"ArialMT" fontSize:15.0f];
lblCompanyName.anchorPoint = ccp(1,0.5);
//lblTurnsSurvived.string = #"1000";
lblCompanyName.positionType = CCPositionTypeNormalized;
lblCompanyName.position = ccp(0.15,0.5);
lblCompanyName.color = [CCColor colorWithRed:242/255.f green:195/255.f blue:17/255.f];
[cell addChild:lblCompanyName];
return cell;
}
-(NSUInteger)tableViewNumberOfRows:(CCTableView *)tableView{
return [self.candidateArray count];
}
-(float)tableView:(CCTableView *)tableView heightForRowAtIndex:(NSUInteger)index{
return 40.f;
}
You need to set multipleTouchEnabled to YES on your instance of CCTableView. I had this same problem and that worked for me.

Keep a uiview highlighted ( change it's alpha ) until another one in tapped

How can i keep a UIVIew highlighted ( change alpha ) until another one is tapped? I have a uiscrollview in which i have loaded several uiview in order to achieve the thumbnail effect. I create them using this method :
_thumbnailScroll.delegate = self;
[_thumbnailScroll setBackgroundColor:[UIColor clearColor]];
[_thumbnailScroll setCanCancelContentTouches:NO];
_thumbnailScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
_thumbnailScroll.clipsToBounds = NO;
_thumbnailScroll.scrollEnabled = YES;
_thumbnailScroll.pagingEnabled = YES;
NSUInteger nimages = 0;
NSInteger tot=0;
CGFloat cx = 0;
for (nimages = 0; nimages < 5 ; nimages++) {
// NSString *imageName = [NSString stringWithFormat:#"thumb%lu.png", (nimages + 1)];
UIImage *image = [UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:#"newPics/thumb/thumb1.png" ]];
if (tot==5) {
break;
}
if (5==nimages) {
nimages=0;
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.height = 150;
rect.size.width = 150;
rect.origin.x = cx;
rect.origin.y = 0;
imageView.frame = rect;
// NSString *propertyName = [NSString stringWithFormat:#"image%lu", (unsigned long)nimages];
//UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(tapGestureCapturedFor1:)];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(onSingleTapGestureRecognized:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
singleTap.delegate = self;
// [imageView add]
[imageView addGestureRecognizer:singleTap];
//[singleTap1 release];
imageView.userInteractionEnabled = YES;
[_thumbnailScroll addSubview:imageView];
_thumbnailScroll.userInteractionEnabled = YES;
// [imageView release];
cx += imageView.frame.size.width+100;
tot++;
}
The above method initializes the image views inside the scroll view and adds a tap gesture to be captured in the following method :
- (void)onSingleTapGestureRecognized:(UITapGestureRecognizer *)singleTapGestureRecognizer
{
UIView *tappedView = [_thumbnailScroll hitTest:[singleTapGestureRecognizer locationInView: _thumbnailScroll] withEvent:nil];
// tappedView.alpha =1.0;
// NSLog(#"image view tag %ld" , (long)tappedView.tag);
// NSLog(#" Description %# " , tappedView.description );
// label.highlighted = YES;
tappedView.alpha = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 5.0 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
tappedView.alpha = 1.0;;
});
}
Now this method highlights the tapped uiview for almost 5 seconds, i am trying to keep it highlighted until i tap on another uiview. How can i achieve that?
Remove this code:
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 5.0 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
tappedView.alpha = 1.0;;
});
And replace with this:
for(UIView *view in _thumbnailScroll.subviews) {
view.alpha = 1.0;
}
This prevents the alpha in your tapped view from going back to 1 after 5 seconds and ensures all the other views have an alpha of zero. Or for a more performant approach, set a pointer to the last view clicked, and instead of looping through each of your ScrollView's subviews, simply set the alpha of the view you've referenced to 1.0. So instead, you'd add a property called lastTappedView and then replace the above code with:
_lastTappedView.alpha = 1.0;
_lastTappedView = tappedView;
singleTap.numberOfTouchesRequired = 1;
numberOfTouch is read-only.

SpriteKit Objective Jump

I got a problem with my code. I added the swipe gesture to jump, but my objective won't jump at all. The NSLog for the Swipe gesture works, so it must be something wrong with my objective code.
-(void)Mensch{
SKTexture * MenschTexture1 = [SKTexture textureWithImageNamed:#"Mensch1"];
MenschTexture1.filteringMode = SKTextureFilteringNearest;
SKTexture * MenschTexture2 = [SKTexture textureWithImageNamed:#"Mensch2"];
MenschTexture2.filteringMode = SKTextureFilteringNearest;
SKAction * Run = [SKAction repeatActionForever:[SKAction animateWithTextures:#[MenschTexture1, MenschTexture2] timePerFrame:0.4]];
Mensch = [SKSpriteNode spriteNodeWithTexture:MenschTexture1];
Mensch.size = CGSizeMake(45, 45);
Mensch.position = CGPointMake(self.frame.size.width / 5, Boden.position.y + 73);
Mensch.zPosition = 2;
Mensch.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:Mensch.size];
Mensch.physicsBody.dynamic = NO;
Mensch.physicsBody.allowsRotation = NO;
Mensch.physicsBody.usesPreciseCollisionDetection = YES;
Mensch.physicsBody.restitution = 0;
[Mensch runAction:Run];
[self addChild:Mensch];
}
- (void)didMoveToView:(SKView *)view
{
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipe:)];
recognizer.direction = UISwipeGestureRecognizerDirectionUp;
[[self view] addGestureRecognizer:recognizer];
}
- (void)handleSwipe:(UISwipeGestureRecognizer *)sender
{
Mensch.physicsBody.velocity = CGVectorMake(0, 0);
[Mensch.physicsBody applyImpulse:CGVectorMake(0, 20)];
NSLog(#"Jump");
}
You need to set
Mensch.physicsBody.dynamic = YES;
According to Apple's documentation about the dynamic property of SKPhysicsBody:
The default value is YES. If the value is NO, then the physics body
ignores all forces and impulses applied to it. This property is
ignored on edge-based bodies; they are automatically static.

iOS CAEmitterLayer how to show animation on uiimageview

I am following this tutorial "http://www.raywenderlich.com/6063/uikit-particle-systems-in-ios-5-tutorial". everything works but I want that effect to go on my image view.
please help where should I make changes
this is code I have in my view controller on which I am showing animation
-(IBAction)ClickOn:(id)sender
{
[fireView startAnimation];
[fireView setIsEmitting:YES];
[self.view bringSubviewToFront:fireView];
[self.view sendSubviewToBack:sample];
}
and this is code in library view class
-(void)startAnimation
{
NSLog(#"awakeFromNib");
//set ref to the layer
fireEmitter = (CAEmitterLayer*)self.layer; //2
//configure the emitter layer
fireEmitter.emitterSize = CGSizeMake(20, 20);
CAEmitterCell* fire = [CAEmitterCell emitterCell];
fire.birthRate = 0;
fire.lifetime = 2.0;
fire.lifetimeRange = 1.5;
fire.color = [[UIColor colorWithRed:236 green:237 blue:237 alpha:0.1] CGColor];
fire.contents = (id)[[UIImage imageNamed:#"Particles_fire.png"] CGImage];
[fire setName:#"fire"];
fire.yAcceleration =
fire.velocity = 0.1;
fire.velocityRange = 80;
fire.emissionRange = 80;
fire.scale = 1.0;
fire.scaleSpeed = 0.1;
fire.spin = 40.5;
CABasicAnimation* ba = [CABasicAnimation animationWithKeyPath:#"emitterPosition"];
ba.fromValue = [NSValue valueWithCGPoint:CGPointMake(150, 400)];
ba.toValue = [NSValue valueWithCGPoint:CGPointMake(300,0)];
ba.duration = 6;
ba.autoreverses = NO;
[fireEmitter addAnimation:ba forKey:nil];
fireEmitter.renderMode = kCAEmitterLayerPoints;
//add the cell to the layer and we're done
fireEmitter.emitterCells = [NSArray arrayWithObject:fire];
fireEmitter.zPosition = 400.0;
}
basically i just want animation to go above uiimageview or uiview, currently it is going behind it

Resources