CATransform3D not being applied properly in custom UICollectionViewFlowLayout - ios6

I'm having a strange issue with custom UICollectionViewFlowLayout, my cells contain an imageView, I apply a zoom effect to my cells... however I think that I'm doing something wrong with the Zoom Effect, it's strange, because my cells get scaled correctly, the problem is that the imageView for some cells is not.
Here's the relevant code (I think) for this issue, (note that If I remove the method: - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect or the CATransform3DMakeScale, the problem doesn't seem to appear.)
///// UICollectionViewController.m
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
HICollectionViewCell *cell = (HICollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:COLLECTION_VIEW_CELL_ID forIndexPath:indexPath];
[self customizeCell:cell atIndexPath:indexPath];
return cell;
}
#pragma mark - CollectionView FlowDelegate
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(200.0f, 200.0f);
}
#pragma mark - "Private" Methods
- (void)customizeCell:(HICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
UIImageView *view = (UIImageView *)[cell.contentView viewWithTag:kCollectionViewCellSubViewTag_imgView];
if (!view.image) {
view.image = [UIImage imageNamed:#"placeholder.png"];
}
}
The Custom Layout Inherits from UICollectionViewFlowLayout
/////// CustomLayout.m
static const CGFloat ACTIVE_DISTANCE = 200.0f;
static const CGFloat ZOOM_FACTOR = 0.3f;
- (id)init
{
if(self = [super init]) {
self.itemSize = CGSizeMake(ITEM_SIZE, ITEM_SIZE);
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.sectionInset = UIEdgeInsetsMake(200.0f, 0.0f, 200.0f, 0.0f);
self.minimumLineSpacing = 50.0f;
}
return self;
}
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
return YES;
}
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
CGRect visibleRect;
visibleRect.origin = self.collectionView.contentOffset;
visibleRect.size = self.collectionView.bounds.size;
for (UICollectionViewLayoutAttributes *attribute in attributes) {
if (CGRectIntersectsRect(attribute.frame, rect)) {
CGFloat distance = CGRectGetMidX(visibleRect) - attribute.center.x;
CGFloat normalizedDistance = distance / ACTIVE_DISTANCE;
// Apply a zoom factor to cells within ACTIVE_DISTANCE
if (ABS(distance) < ACTIVE_DISTANCE) {
CGFloat zoom = 1.0f + ZOOM_FACTOR * (1.0f - ABS(normalizedDistance));
attribute.transform3D = CATransform3DMakeScale(zoom, zoom, 1.0);
attribute.zIndex = round(zoom);
}
}
}
return attributes;
}
As the FlowLayout appears everything looks fine.
Then I start to scroll and I notice that the background layer of the cells to the right starts to show off (backgroundColor is orange)
As you can see, after two cells, the third one ( that starts to appear, looks OK again ).
Maybe it's an issue with the cell queue and dequeue (and the imageView being re-used or something?).

Related

SceneKit: how to create chessboard pattern for SCNFloor from image?

The goal is to create an infinite chessboard pattern.
Using a SCNFloor and the attached image, we produce something close but not quite like a chessboard. Some black squares merge where they shouldn't.
We tried different values for Scale, WrapS, WrapT, Min filter, Map filter, and Mip filter. The screenshot shows the current values.
Is the underlying image not correct, or what setting do we need to change for the SCNFloor?
Repeated image:
Result:
#import "GameViewController.h"
#interface GameViewController ()
#property (nonatomic) CGFloat chessBoardWidth;
#property (nonatomic) CGFloat chessBoardDepth;
#property (nonatomic) CGFloat tileWidth;
#property (nonatomic) CGFloat tileDepth;
#property (nonatomic, getter=isOdd) BOOL odd;
#end
#implementation GameViewController
-(instancetype)init {
self = [super init];
if(self) {
self.chessBoardWidth = 10.0f;
self.chessBoardDepth = 10.0f;
self.tileWidth = 1.0f;
self.tileDepth = 1.0f;
}
return self;
}
-(void)awakeFromNib
{
[super awakeFromNib];
// create a new scene
SCNScene *scene = [SCNScene sceneNamed:#"art.scnassets/chessboard.scn"];
// create and add a camera to the scene
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
[scene.rootNode addChildNode:cameraNode];
// place the camera
cameraNode.position = SCNVector3Make(0, 0, 150);
// create and add a light to the scene
SCNNode *lightNode = [SCNNode node];
lightNode.light = [SCNLight light];
lightNode.light.type = SCNLightTypeOmni;
lightNode.position = SCNVector3Make(0, 10, 10);
[scene.rootNode addChildNode:lightNode];
// create and add an ambient light to the scene
SCNNode *ambientLightNode = [SCNNode node];
ambientLightNode.light = [SCNLight light];
ambientLightNode.light.type = SCNLightTypeAmbient;
ambientLightNode.light.color = [NSColor darkGrayColor];
[scene.rootNode addChildNode:ambientLightNode];
// Material
SCNMaterial *blackMaterial = [SCNMaterial material];
blackMaterial.diffuse.contents = [NSColor blackColor];
SCNMaterial *whiteMaterial = [SCNMaterial material];
whiteMaterial.diffuse.contents = [NSColor whiteColor];
// Geometry
SCNPlane *blackTile = [[SCNPlane alloc] init];
blackTile.firstMaterial = blackMaterial;
SCNPlane *whiteTile = [[SCNPlane alloc] init];
whiteTile.firstMaterial = whiteMaterial;
// Parent node
SCNNode *parentNode = [[SCNNode alloc] init];
[scene.rootNode addChildNode:parentNode];
self.odd = YES;
for (uint x=0; x < self.chessBoardWidth; x++) {
for (uint z=0; z < self.chessBoardDepth; z++) {
// Add tile
SCNNode *tileNode = [[SCNNode alloc] init];
if(self.isOdd) {
tileNode.geometry = blackTile;
} else {
tileNode.geometry = whiteTile;
}
[parentNode addChildNode:tileNode];
// Position tile
tileNode.position = SCNVector3Make(self.tileWidth * x, 0, self.tileDepth * z);
// Alternate
if(self.isOdd) {
self.odd = NO;
} else {
self.odd = YES;
}
}
}
// set the scene to the view
self.gameView.scene = scene;
// allows the user to manipulate the camera
self.gameView.allowsCameraControl = YES;
// show statistics such as fps and timing information
self.gameView.showsStatistics = YES;
// configure the view
self.gameView.backgroundColor = [NSColor grayColor];
}
#end

Unexpected '#' in xcode after upgrade of xcode

Can someone help me out with why this error showed up after I upgraded to the newest version of xcode? The app was working fine prior to this, but this syntax error prevents compiling now. I am getting the error at
#pragma mark -#property (nonatomic, k Constants,
and also I get a missing #end error.
Sorry for posting the entire page, but I wanted to make sure I provided enough to get assistance.
#import "MBProgressHUD.h"
#interface MBProgressHUD ()
(void)hideUsingAnimation:(BOOL)animated;
(void)showUsingAnimation:(BOOL)animated;
(void)fillRoundedRect:(CGRect)rect inContext:(CGContextRef)context;
(void)done;
(void)updateLabelText:(NSString *)newText;
(void)updateDetailsLabelText:(NSString *)newText;
(void)updateProgress;
(void)updateIndicators;
(void)handleGraceTimer:(NSTimer *)theTimer;
(void)handleMinShowTimer:(NSTimer *)theTimer;
#property (retain) UIView *indicator;
#property (assign) float width;
#property (assign) float height;
#property (retain) NSTimer *graceTimer;
#property (retain) NSTimer *minShowTimer;
#property (retain) NSDate *showStarted;
#end
#implementation MBProgressHUD
#pragma mark -
#pragma mark Accessors
#synthesize mode;
#synthesize delegate;
#synthesize labelText;
#synthesize detailsLabelText;
#synthesize opacity;
#synthesize labelFont;
#synthesize detailsLabelFont;
#synthesize progress;
#synthesize indicator;
#synthesize width;
#synthesize height;
#synthesize xOffset;
#synthesize yOffset;
#synthesize graceTime;
#synthesize minShowTime;
#synthesize graceTimer;
#synthesize minShowTimer;
#synthesize taskInProgress;
#synthesize showStarted;
(void)setMode:(MBProgressHUDMode)newMode {
if (mode && (mode == newMode)) {
return;
}
mode = newMode;
[self performSelectorOnMainThread:#selector(updateIndicators) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
}
(void)setLabelText:(NSString *)newText {
[self performSelectorOnMainThread:#selector(updateLabelText:) withObject:newText waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
}
(void)setDetailsLabelText:(NSString *)newText {
[self performSelectorOnMainThread:#selector(updateDetailsLabelText:) withObject:newText waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
}
(void)setProgress:(float)newProgress {
progress = newProgress;
if (mode == MBProgressHUDModeDeterminate) {
[self performSelectorOnMainThread:#selector(updateProgress) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
}
}
#pragma mark -
#pragma mark Accessor helpers
(void)updateLabelText:(NSString *)newText {
if (labelText != newText) {
[labelText release];
labelText = [newText copy];
}
}
(void)updateDetailsLabelText:(NSString *)newText {
if (detailsLabelText != newText) {
[detailsLabelText release];
detailsLabelText = [newText copy];
}
}
(void)updateProgress {
[(MBRoundProgressView *)indicator setProgress:progress];
}
(void)updateIndicators {
if (indicator) {
[indicator removeFromSuperview];
}
self.indicator = nil;
if (mode == MBProgressHUDModeDeterminate) {
self.indicator = [[MBRoundProgressView alloc] initWithDefaultSize];
}
else {
self.indicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[(UIActivityIndicatorView *)indicator startAnimating];
}
[self addSubview:indicator];
}
**#pragma mark -
#property (nonatomic, k Constants**
#define MARGIN 20.0
#define PADDING 4.0
#define LABELFONTSIZE 22.0
#define LABELDETAILSFONTSIZE 16.0
#define PI 3.14159265358979323846
#pragma mark -
#pragma mark Lifecycle methods
(id)initWithWindow:(UIWindow *)window {
#property (nonatomic, nonatomic, nonatomic, [self initWithView:window];
}
(id)initWithView:(UIView *)view {
initializer above)
if (!view) {
#property (nonatomic, ion raise:#"MBProgressHUDViewIsNillException"
format:#"The view used in the MBProgressHUD initializer is nil."];
}
return [self initWithFrame:view.bounds];
}
(id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.mode = MBProgressHUDModeIndeterminate;
self.labelText = nil;
self.detailsLabelText = nil;
self.opacity = 0.9;
self.labelFont = [UIFont boldSystemFontOfSize:LABELFONTSIZE];
self.detailsLabelFont = [UIFont boldSystemFontOfSize:LABELDETAILSFONTSIZE];
self.xOffset = 0.0;
self.yOffset = 0.0;
self.graceTime = 0.0;
self.minShowTime = 0.0;
self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.alpha = 0.0;
label = [[UILabel alloc] initWithFrame:self.bounds];
detailsLabel = [[UILabel alloc] initWithFrame:self.bounds];
taskInProgress = NO;
}
return self;
}
(void)dealloc {
[indicator release];
[label release];
[detailsLabel release];
[labelText release];
[detailsLabelText release];
[graceTimer release];
[minShowTimer release];
[showStarted release];
[super dealloc];
}
#pragma mark -
#pragma mark Layout
(void)layoutSubviews {
CGRect frame = self.bounds;
#property (nonatomic, indFrame = indicator.bounds;
self.width = indFrame.size.width + 2 * MARGIN;
self.height = indFrame.size.height + 2 * MARGIN;
indFrame.origin.x = floor((frame.size.width - indFrame.size.width) / 2) + self.xOffset;
indFrame.origin.y = floor((frame.size.height - indFrame.size.height) / 2) + self.yOffset;
indicator.frame = indFrame;
if (nil != self.labelText) {
CGSize dims = [self.labelText sizeWithFont:self.labelFont];
clip the label width
float lHeight = dims.height;
float lWidth;
if (dims.width <= (frame.size.width - 2 * MARGIN)) {
lWidth = dims.width;
}
else {
lWidth = frame.size.width - 4 * MARGIN;
}
label.font = self.labelFont;
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentCenter;
label.opaque = NO;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = self.labelText;
if (self.width < (lWidth + 2 * MARGIN)) {
self.width = lWidth + 2 * MARGIN;
}
self.height = self.height + lHeight + PADDING;
indFrame.origin.y -= (floor(lHeight / 2 + PADDING / 2));
indicator.frame = indFrame;
// Set the label position and dimensions
CGRect lFrame = CGRectMake(floor((frame.size.width - lWidth) / 2) + xOffset,
floor(indFrame.origin.y + indFrame.size.height + PADDING),
lWidth, lHeight);
label.frame = lFrame;
[self addSubview:label];
// Add details label delatils text was set
if (nil != self.detailsLabelText) {
// Get size of label text
dims = [self.detailsLabelText sizeWithFont:self.detailsLabelFont];
// Compute label dimensions based on font metrics if size is larger than max then clip the label width
lHeight = dims.height;
if (dims.width <= (frame.size.width - 2 * MARGIN)) {
lWidth = dims.width;
}
else {
lWidth = frame.size.width - 4 * MARGIN;
}
// Set label properties
detailsLabel.font = self.detailsLabelFont;
detailsLabel.adjustsFontSizeToFitWidth = NO;
detailsLabel.textAlignment = UITextAlignmentCenter;
detailsLabel.opaque = NO;
detailsLabel.backgroundColor = [UIColor clearColor];
detailsLabel.textColor = [UIColor whiteColor];
detailsLabel.text = self.detailsLabelText;
// Update HUD size
if (self.width < lWidth) {
self.width = lWidth + 2 * MARGIN;
}
self.height = self.height + lHeight + PADDING;
// Move indicator to make room for the new label
indFrame.origin.y -= (floor(lHeight / 2 + PADDING / 2));
indicator.frame = indFrame;
// Move first label to make room for the new label
lFrame.origin.y -= (floor(lHeight / 2 + PADDING / 2));
label.frame = lFrame;
// Set label position and dimensions
CGRect lFrameD = CGRectMake(floor((frame.size.width - lWidth) / 2) + xOffset,
lFrame.origin.y + lFrame.size.height + PADDING, lWidth, lHeight);
detailsLabel.frame = lFrameD;
[self addSubview:detailsLabel];
}
}
}
#pragma mark -
#pragma mark Showing and execution
- (void)show:(BOOL)animated {
useAnimation = animated;
// If the grace time is set postpone the HUD display
if (self.graceTime > 0.0) {
self.graceTimer = [NSTimer scheduledTimerWithTimeInterval:self.graceTime
target:self
selector:#selector(handleGraceTimer:)
userInfo:nil
repeats:NO];
}
// ... otherwise show the HUD imediately
else {
[self setNeedsDisplay];
[self showUsingAnimation:useAnimation];
}
}
- (void)hide:(BOOL)animated {
useAnimation = animated;
// If the minShow time is set, calculate how long the hud was shown,
// and pospone the hiding operation if necessary
if (self.minShowTime > 0.0 && showStarted) {
NSTimeInterval interv = [[NSDate date] timeIntervalSinceDate:showStarted];
if (interv < self.minShowTime) {
self.minShowTimer = [NSTimer scheduledTimerWithTimeInterval:(self.minShowTime - interv)
target:self
selector:#selector(handleMinShowTimer:)
userInfo:nil
repeats:NO];
return;
}
}
// ... otherwise hide the HUD immediately
[self hideUsingAnimation:useAnimation];
}
- (void)handleGraceTimer:(NSTimer *)theTimer {
// Show the HUD only if the task is still running
if (taskInProgress) {
[self setNeedsDisplay];
[self showUsingAnimation:useAnimation];
}
}
- (void)handleMinShowTimer:(NSTimer *)theTimer {
[self hideUsingAnimation:useAnimation];
}
- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated {
methodForExecution = method;
targetForExecution = [target retain];
objectForExecution = [object retain];
// Launch execution in new thread
taskInProgress = YES;
[NSThread detachNewThreadSelector:#selector(launchExecution) toTarget:self withObject:nil];
// Show HUD view
[self show:animated];
}
- (void)launchExecution {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Start executing the requested task
[targetForExecution performSelector:methodForExecution withObject:objectForExecution];
// Task completed, update view in main thread (note: view operations should
// be done only in the main thread)
[self performSelectorOnMainThread:#selector(cleanUp) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void*)context {
[self done];
}
- (void)done {
isFinished = YES;
// If delegate was set make the callback
self.alpha = 0.0;
if(delegate != nil && [delegate conformsToProtocol:#protocol(MBProgressHUDDelegate)]) {
if([delegate respondsToSelector:#selector(hudWasHidden)]) {
[delegate performSelector:#selector(hudWasHidden)];
}
}
}
- (void)cleanUp {
taskInProgress = NO;
self.indicator = nil;
[targetForExecution release];
[objectForExecution release];
[self hide:useAnimation];
}
#pragma mark -
#pragma mark Fade in and Fade out
- (void)showUsingAnimation:(BOOL)animated {
self.showStarted = [NSDate date];
// Fade in
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.40];
self.alpha = 1.0;
[UIView commitAnimations];
}
else {
self.alpha = 1.0;
}
}
- (void)hideUsingAnimation:(BOOL)animated {
// Fade out
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.40];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationFinished: finished: context:)];
// 0.02 prevents the hud from passing through touches during the animation the hud will get completely hidden
// in the done method
self.alpha = 0.02;
[UIView commitAnimations];
}
else {
self.alpha = 0.0;
[self done];
}
}
#pragma mark BG Drawing
- (void)drawRect:(CGRect)rect {
// Center HUD
CGRect allRect = self.bounds;
// Draw rounded HUD bacgroud rect
CGRect boxRect = CGRectMake(((allRect.size.width - self.width) / 2) + self.xOffset,
((allRect.size.height - self.height) / 2) + self.yOffset, self.width, self.height);
CGContextRef ctxt = UIGraphicsGetCurrentContext();
[self fillRoundedRect:boxRect inContext:ctxt];
}
- (void)fillRoundedRect:(CGRect)rect inContext:(CGContextRef)context {
float radius = 10.0f;
CGContextBeginPath(context);
CGContextSetGrayFillColor(context, 0.0, self.opacity);
CGContextMoveToPoint(context, CGRectGetMinX(rect) + radius, CGRectGetMinY(rect));
CGContextAddArc(context, CGRectGetMaxX(rect) - radius, CGRectGetMinY(rect) + radius, radius, 3 * M_PI / 2, 0, 0);
CGContextAddArc(context, CGRectGetMaxX(rect) - radius, CGRectGetMaxY(rect) - radius, radius, 0, M_PI / 2, 0);
CGContextAddArc(context, CGRectGetMinX(rect) + radius, CGRectGetMaxY(rect) - radius, radius, M_PI / 2, M_PI, 0);
CGContextAddArc(context, CGRectGetMinX(rect) + radius, CGRectGetMinY(rect) + radius, radius, M_PI, 3 * M_PI / 2, 0);
CGContextClosePath(context);
CGContextFillPath(context);
}
#end
#implementation MBRoundProgressView
- (id)initWithDefaultSize {
return [super initWithFrame:CGRectMake(0.0f, 0.0f, 37.0f, 37.0f)];
}
- (void)drawRect:(CGRect)rect {
CGRect allRect = self.bounds;
CGRect circleRect = CGRectMake(allRect.origin.x + 2, allRect.origin.y + 2, allRect.size.width - 4,
allRect.size.height - 4);
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw background
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); // white
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.1); // translucent white
CGContextSetLineWidth(context, 2.0);
CGContextFillEllipseInRect(context, circleRect);
CGContextStrokeEllipseInRect(context, circleRect);
// Draw progress
float x = (allRect.size.width / 2);
float y = (allRect.size.height / 2);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0); // white
CGContextMoveToPoint(context, x, y);
CGContextAddArc(context, x, y, (allRect.size.width - 4) / 2, -(PI / 2), (self.progress * 2 * PI) - PI / 2, 0);
CGContextClosePath(context);
CGContextFillPath(context);
}
#end
The line throwing the error makes no sense.
#pragma mark -
#property (nonatomic, k Constants
the #pragma mark - puts a line in the drop down list but what is the next line supposed to do?
if you are declaring a property, then you haven't closed the bracket after nonatomic, but when what is k Constants supposed to be. Are you sure you didn't change the file?

UICollectionViews to select 2 Images, one on top of the other

I have mainView with an image displayed (Using Storyboards and imageViews and CollectionViews) when I select an cell from my CollectionView (in a popOver).
How do I create another (popover containing a UiCollectionView) that let's me select an image and place that second image on top of the one I already have displayed?
#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
// Return the number of sections.
// return [_carImages count] / 2;
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_carImages count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// CellTasteCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
// image = [[UIImage imageNamed:[_carImages objectAtIndex:indexPath.row]];
// cell.imageView.image = image;
// return cell;
NSLog(#"INDEX PATH roe %#",[_carImages objectAtIndex:indexPath.row]);
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
/*
UIImageView *brickAnim = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile: imageFilePath]];
brickAnim.frame = CGRectMake(0, 0, 62, 57);
[cell.contentView addSubview:brickAnim];
cell.layer.borderColor=[UIColor whiteColor].CGColor;
cell.layer.borderWidth=2.0;
*/ cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[_carImages objectAtIndex:indexPath.row]]];
return cell;
/* MyCollectionViewCell *myCell = [collectionView
dequeueReusableCellWithReuseIdentifier:#"MyCell"
forIndexPath:indexPath];
UIImage *image;
int row = [indexPath row];
image = [UIImage imageNamed:_carImages[row]];
myCell.imageView.image = image;
return myCell;*/
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
// UIImage *image =[UIImage imageNamed: [_carImages objectAtIndex:indexPath.row]];
return CGSizeMake(40, 40);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(20, 20, 20, 20);
}
#pragma mark -
#pragma mark UICollectionViewFlowLayoutDelegate
/*-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *image;
int row = [indexPath row];
image = [UIImage imageNamed:_carImages[row]];
return image.size;
}*/
- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition{
}

IOS 6 UITableViewCellEditingStyle Overlapping TableViewCell Labels

I am working with IOS 6 UITableView and my problem is that whenever i put the table view into edit mode, the edit control that appears next to the table view cell of deletestyle ( UITableViewCellEditingStyleDelete ) overlaps two labels ( xyzname and xyzcollege ).
I did not have this problem in IOS 5 (with same code).
CODE:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle]pathForResource:#"friends"ofType:#"plist"];
NSDictionary *xyz = [[NSDictionary alloc]initWithContentsOfFile:path];
_names = [xyz objectForKey:#"name"];
_colls = [xyz objectForKey:#"college"];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
NSInteger count =_names.count;
if(self.editing)
{
count++;
}
return count;
}
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
saumyaTableViewCell *cell;
cell = [_saumyaTable dequeueReusableCellWithIdentifier:#"saumyacell"];
if(indexPath.row < _names.count)
{
cell.xyzname.text = [_names objectAtIndex:indexPath.row];
cell.xyzcollege.text = [_colls objectAtIndex:indexPath.row];
}
else
{
cell.xyzname.text = #"Add name.";
cell.xyzcollege.text = #"Add College";
cell.editingAccessoryType =
UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
-(void)setEditing:(BOOL)editing animated:(BOOL) animated
{
if( editing != self.editing )
{
[super setEditing:editing animated:animated];
[_saumyaTable setEditing:editing animated:animated];
NSArray *indexes = [NSArray arrayWithObject:
[NSIndexPath indexPathForRow:_names.count inSection:0]];
if (editing == YES )
{
[_saumyaTable insertRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationLeft];
}
else
{
[_saumyaTable deleteRowsAtIndexPaths:indexes
withRowAnimation:UITableViewRowAnimationLeft];
}
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row < _names.count)
{
return UITableViewCellEditingStyleDelete;
}
else
{
return UITableViewCellEditingStyleInsert;
}
}
IMAGE DESCRIPTION:
1.UITableViewCell has two labels(xyzname and xyzcollege)
2.UITableViewCellEditingStyleDelete overlaps these two labels when cell goes into edit mode
What is to be done if i want those labels to automatically animate on the right side when my view goes into the edit mode and again animate to their original positions after coming out of the edit mode?
THANK YOU

uikeyboard leaves a black portion on top on navigation

I have a form on the ipad which has many textfield and a button at the end. There are some fields which come under the keyboard when it is active. In order to pull the hidden texfield behind the keyboard to be visible I am using the following code.
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField:textField up:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
_scrollView.frame=CGRectMake(0, 0, 1024, 655);
[self animateTextField:textField up:NO];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
CGPoint temp = [textField.superview convertPoint:textField.frame.origin toView:nil];
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait)
{
// NSLog(#"portrait");
if(up)
{
int moveUpValue = temp.y+textField.frame.size.height;
animatedDis = 264-(1024-moveUpValue-5);
}
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown)
{
if(up)
{
int moveUpValue = 1004-temp.y+textField.frame.size.height;
animatedDis = 264-(1004-moveUpValue-5);
}
}
else if(orientation == UIInterfaceOrientationLandscapeLeft)
{
if(up)
{
int moveUpValue = temp.x+textField.frame.size.height;
animatedDis = 352-(768-moveUpValue-5);
}
}
else
{
if(up)
{
int moveUpValue = 768-temp.x+textField.frame.size.height;
animatedDis = 352-(768-moveUpValue-5);
_scrollView.frame = CGRectMake(0, 0, 1024, 655-240);
}
}
if(animatedDis>0)
{
const int movementDistance = animatedDis;
const float movementDuration = 0.3f;
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: nil context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
if (orientation == UIInterfaceOrientationPortrait)
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
else if(orientation == UIInterfaceOrientationLandscapeLeft)
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
else
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
[UIView commitAnimations];
}
}
I am also using the scroll view. My issue is that when the keyboard is active and i press my button it take me to the next screen. Now if i navigate back, the keyboard is active and the prior animations are set. Now if i hide the keyboard, the entire view scrolls down leaving a black portion on top. How to handle this situation?
Okay. After much research I found a simple method. It is the use of notifications.
In my viewDidLoad i added these two keyboard notifications.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWasShown:) name: UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
These are the 2 selector methods:
-(void)keyboardWasShown:(NSNotification *)aNotification
{
if (displayKeyboard==YES) {
return;
}
NSDictionary* info = [aNotification userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
//NSValue* aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
NSLog(#"kbw====%fkbh====%f",keyboardSize.width,keyboardSize.height);
offset = _scrollView.contentOffset;
CGRect viewFrame = _scrollView.frame;
NSLog(#"svw====%fsvh===%f",viewFrame.size.width,viewFrame.size.height);
viewFrame.size.height -= keyboardSize.height-49;
NSLog(#"new view hgt =====%f",viewFrame.size.height);
_scrollView.frame = viewFrame;
CGRect textFieldRect = [activeField frame];
textFieldRect.origin.y += 10;
[_scrollView scrollRectToVisible: textFieldRect animated:YES];
displayKeyboard = YES;
}
-(void)keyboardWillBeHidden:(NSNotification *)aNotification
{
if (!displayKeyboard) {
return;
}
_scrollView.frame = CGRectMake(0, 0, 1024, 655);
_scrollView.contentOffset =offset;
displayKeyboard = NO;
}
-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField {
activeField = textField;
return YES;
}
displayKeyboard, offset and activeField are declared in .h file.
Also remember to remove the notifications in viewDidDisappear:animated
Although this method is quite different than the previous one stated, this one does not leave a black portion on the top while navigating between classes when the uikeyboard is active.
Also what i noticed was if i used the deprecated UIKeyboardBoundsUserInfoKey i used to get the correct width and height of the keyboard(i am working only in landscape mode). Whereas when i used UIKeyboardFrameBeginUserInfoKey the width and height values were interchanged. I am still trying to figure out this problem.
Also when the keyboard used to appear, a fixed space of 49px was appended to above it. I assumed that that was my tabbar height and therefore subtracted 49.

Resources