Cocos2D v3 CCTableView not scrolling - ios

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.

Related

How do i get custom UIView in table view cell

I have a Custom UIView inside my prototype cell in a nd iOS 8.2 app before it was a regular UIImage and i was getting it back fine with [currentCell viewWithTag:200]; inside my UITableView cellForRowIndexPath method. But after i have made a custom uiview and replaced the uiimage it always returns nil..
edit
After trying to add a new label to a working menu controller that is way more simple just loops over a array of strings. and setting the tag and in the loop (that is already printing the correct value out for the menu) it can't find the newly added label. is it possible to somehow not get the tags compiled ?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *currentCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Lists *listItem = [lists objectAtIndex:indexPath.row];
if(currentCell == nil){
currentCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//THIS ALLWAYS RETUNS nil
ShadedBadgeImage *cellImage = (ShadedBadgeImage *)[currentCell viewWithTag:200];
//UIView *cellImage = (UIView *)[currentCell viewWithTag:200];
//cellImage.completedProcentage = 2.0 * listItem.id.doubleValue;
UILabel *cellTitle = (UILabel *) [currentCell viewWithTag:101];
UILabel *cellDescription = (UILabel *)[currentCell viewWithTag:102];
cellTitle.text = listItem.id.stringValue;
cellDescription.text = listItem.shortText;
return currentCell;
And my custom uiview. that is using the layoutSubviews to render the masked image and progress bar.
IB_DESIGNABLE
#implementation ShadedBadgeImage {
double lineWidth;
CAShapeLayer *backgroundLayer;
CAShapeLayer *coloredLayer;
CALayer *imageLayer;
}
- (void)baseInit {
lineWidth = 5.0;
[self updateStroke];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self baseInit];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
[self baseInit];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
//Adds the background ring layer
if(backgroundLayer == nil)
{
backgroundLayer = [[CAShapeLayer alloc] init];
CGRect rect = CGRectInset(self.bounds, lineWidth/2.0, lineWidth/2.0);
UIBezierPath *roundPath = [UIBezierPath bezierPathWithOvalInRect:rect];
backgroundLayer.path = roundPath.CGPath;
backgroundLayer.fillColor = nil;
backgroundLayer.lineWidth = lineWidth;
backgroundLayer.strokeColor = [UIColor colorWithWhite:0.5 alpha:0.05].CGColor;
[self.layer addSublayer:backgroundLayer];
}
backgroundLayer.frame = self.layer.frame;
//Adds the color ring layer
if(coloredLayer == nil)
{
coloredLayer = [[CAShapeLayer alloc] init];
CGRect rect = CGRectInset(self.bounds, lineWidth/2.0, lineWidth/2.0);
UIBezierPath *roundPath = [UIBezierPath bezierPathWithOvalInRect:rect];
coloredLayer.path = roundPath.CGPath;
coloredLayer.fillColor = nil;
coloredLayer.lineWidth = lineWidth;
coloredLayer.strokeColor = [UIColor blueColor].CGColor;
coloredLayer.anchorPoint = CGPointMake(0.5, 0.5);
coloredLayer.transform = CATransform3DRotate(coloredLayer.transform, -M_PI/2, 0, 0, 1);
[self.layer addSublayer:coloredLayer];
}
coloredLayer.frame = self.layer.frame;
//Adds the color ring layer
if(imageLayer == nil)
{
CAShapeLayer *imageMask = [[CAShapeLayer alloc] init];
CGRect insertBounds = CGRectInset(self.bounds, lineWidth + 3.0, lineWidth + 3.0);
UIBezierPath *innerPath = [UIBezierPath bezierPathWithOvalInRect:insertBounds];
imageMask.path = innerPath.CGPath;
imageMask.fillColor = [UIColor grayColor].CGColor;
imageMask.frame = self.bounds;
[self.layer addSublayer:imageMask];
imageLayer = [[CALayer alloc] init];
imageLayer.mask = imageMask;
imageLayer.frame = self.layer.frame;
imageLayer.backgroundColor =[UIColor grayColor].CGColor;
imageLayer.contentsGravity = kCAGravityResizeAspectFill;
[self.layer addSublayer:imageLayer];
}
[self updateStroke];
}
- (void) updateStroke{
if (coloredLayer != nil)
{
coloredLayer.strokeEnd = self.completedProcentage;
}
if(self.image != nil)
{
imageLayer.contents = (__bridge id)([self.image CGImage]);
}
}
#end
As the comments says, dont use tags go for custom UITableCellViews for more control

iOS UITextView Always scroll to bottom

I have this scenario: when I click on a UITextView, it will either expand or shrink. But every time the UITextView shrinks, the content scroll down to the bottom.
I've tried
[textView setContentOffset:CGPointZero animated:YES];
textView.scrollsToTop = YES;
But none of them works.
Here is the screenshot:
Here is the code:
- (IBAction)tapText:(id)sender {
NSLog(#"tap text view");
[self addBoundsSpringAnimationToView:self.movieTextView];
}
- (void) addBoundsSpringAnimationToView:(UITextView *)textView {
POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
if (expand) {
NSLog(#"expand");
self.bgUIImageView.hidden = YES;
self.blurredImageView.hidden = NO;
anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0.0f, 320.0f, 807.0f)];
anim.springBounciness = 18;
} else {
NSLog(#"Shrink");
self.bgUIImageView.hidden = NO;
self.blurredImageView.hidden = YES;
anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 355.0f, 320.0f, 225.0f)];
}
expand = !expand;
anim.springSpeed = 10;
[textView pop_addAnimation:anim forKey:#"popBounds"];
}
Is it related to the Facebook Pop animation?
Thanks!

IOS RoundView make child ImageView to be rounded

I've created this custom UIView named RoundView:
#import <QuartzCore/QuartzCore.h>
#implementation RoundedView
+(UIColor *)grayUIColor {
return [UIColor colorWithRed:161.0/255.0 green:157.0/255.0 blue:164.0/255.0 alpha:1.0];
}
+(UIColor *)darkBlueUIColor {
return [UIColor colorWithRed:86.0/255.0 green:88.0/255.0 blue:87.0/255.0 alpha:1];
}
+(UIColor *)greenUIColor {
return [UIColor colorWithRed:51.0/255.0 green:141.0/255.0 blue:130.0/255.0 alpha:1];
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self)
{
//add pico icon as default image
_defaultImage = [UIImage imageNamed:#"actionBar_pico_icon"];
_isCreated = NO;
}
return self;
}
-(UIView*)createRoundViewWithBorder:(UIColor*)borderColor andPaddingColor:(UIColor*)paddingColor{
_borderColor = borderColor;
_paddingBackgroundColor = paddingColor;
[self setViewAppearance];
[self addImageToView];
_isCreated = YES;
return self;
}
/**
Set the current view appearance
*/
-(void) setViewAppearance {
self.layer.borderWidth = 1.5;
self.layer.borderColor = [_borderColor CGColor];
self.backgroundColor = _paddingBackgroundColor;
}
-(void) addImageToView {
CGRect frame = CGRectMake(0, 0, self.frame.size.width - 5, self.frame.size.height - 5);
_imageView = [[UIImageView alloc] initWithFrame:frame];
//calculate center x
float x = (self.frame.size.width - _imageView.frame.size.width) / 2;
//calculate center y
float y = (self.frame.size.height - _imageView.frame.size.height) / 2;
//create new frame
frame = CGRectMake(x, y, _imageView.frame.size.width, _imageView.frame.size.height);
_imageView.image = _defaultImage;
_imageView.frame = frame;
_imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:_imageView];
[self makeViewRounded:_imageView];
[self makeViewRounded:self];
}
-(UIView*) makeViewRounded:(UIView*)view {
//set the look of the image
view.layer.cornerRadius= self.frame.size.height /2;
view.layer.opaque = NO;
view.layer.masksToBounds = YES;
return view;
}
-(void)updateImage:(UIImage *)image {
_image = image;
_imageView.image = image;
}
-(void)reset {
[self updateImage:_defaultImage];
}
#end
an example for the output will be :
If you look closely you will notice that the border is a circle, but the image view has edges.
How can i make the Image smooth as well ?
self.imgViewbg.layer.cornerRadius = self.imgViewbg.frame.size.width / 2;
self.imgViewbg.clipsToBounds = YES;
u Can Try This Code. And Implement in your Project..
It Will Definetly Work.. for u
I think the problem seems to be here:
view.layer.cornerRadius= self.frame.size.height /2;
Try giving it a constant small number and see the change. May be the height/2 is not making a perfect circle. You can give a smaller value than height/2 and see the change. It a wild guess by watching your image.

UIKit Particle Systems in ios7. Number of particles increased

The particle system on ios7 seem to be working different, than on ios6 and ios5. The number of particles increased.
The same issue happens with all particle effects in the app.
The only working solution is to check, if it is ios7 and decrease the particle birth rate. Is there a better solution?
The code of particle emitter view.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//initialize the emitter
_emitter = (CAEmitterLayer*)self.layer;
_emitter.emitterPosition = CGPointMake(self.bounds.size.width /2, self.bounds.size.height/2 );
_emitter.emitterSize = self.bounds.size;
_emitter.emitterMode = kCAEmitterLayerAdditive;
_emitter.emitterShape = kCAEmitterLayerRectangle;
}
return self;
}
- (void)didMoveToSuperview
{
//Check if parent is initialized
[super didMoveToSuperview];
if (self.superview==nil) return;
//Load png
UIImage* texture = self.explosionImage; //[UIImage imageNamed:#"particle.png"];
NSAssert(texture, #"particle.png not found");
//Create a new emitter cell
CAEmitterCell* emitterCell = [CAEmitterCell emitterCell];
//Set the cell’s contents property to the texture you loaded
emitterCell.contents = (__bridge id)[texture CGImage];
//Name the cell “cell”
emitterCell.name = #"cell";
//Parameters
emitterCell.birthRate = self.birthRate;// 40;//1000
emitterCell.lifetime = 2.8;
emitterCell.lifetimeRange = 0.7;
//Set the cell’s color to randomly vary its components
if (!self.explosionColor) {
emitterCell.blueRange = 0.33;
emitterCell.blueSpeed = -0.33;
emitterCell.redRange = 0.33;
emitterCell.redSpeed = -0.33;
emitterCell.greenRange = 0.33;
emitterCell.greenSpeed = -0.33;
}
//Explosion color
if (self.explosionColor) emitterCell.color = [self.explosionColor CGColor];
//velocity
emitterCell.velocity = IS_IPAD?40:20;//160
emitterCell.velocityRange = RANDOMF(10, 20);//15
//Alpha
emitterCell.alphaSpeed = -0.73;
emitterCell.alphaRange = 0.9;
//Scale
emitterCell.scale = IS_IPAD?0.6:0.30;//0.5
emitterCell.scaleRange = 0.6;//0.5
emitterCell.scaleSpeed = 0;
//Range
emitterCell.emissionRange = M_PI*2;//2
//Add the cell to the emitter layer
_emitter.emitterCells = #[emitterCell];
[self performSelector:#selector(disableEmitterCell) withObject:nil afterDelay:self.cellIsEmitting];
[self performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:self.emittingInView];
}
When running on an iOS7, it looks as if the particle system started animating earlier than the time the emitter layer is added.
It is probably a bug, and, hopefully, will be solved in future.
For now, to get a similar behavior as on iOS6, the CAEmitterLayer's beginTime can be set to the current time:
_emitter.beginTime = CACurrentMediaTime();

UISwipeGestureRecognizer detecting swiped object

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];
}}

Resources