not able to tap on MKPinAnnotationView Second Time - ios

I have created Custom annotation by using this code.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *const AnnotatioViewReuseID = #"AnnotatioViewReuseID";
// MKAnnotationView
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotatioViewReuseID];
if (!annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotatioViewReuseID];
}
if ([annotation isKindOfClass:[FBAnnotationCluster class]]) {
FBAnnotationCluster *cluster = (FBAnnotationCluster *)annotation;
cluster.title = [NSString stringWithFormat:#"%lu", (unsigned long)cluster.annotations.count];
UIView *view = [[UIView alloc]init];
view.backgroundColor = [UIColor colorWithRed:33.0/255.0 green:191.0/255.0 blue:133.0/255.0 alpha:1.0];
UILabel *label = [[UILabel alloc]init];
label.text = cluster.title;
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;
UIFont *font = [UIFont fontWithName:#"Avenir-Medium" size:14.0];
label.font = font;
label.frame = CGRectMake(0, 0, [self widthOfString:label.text]+20, [self widthOfString:label.text]+20);
view.frame = CGRectMake(0, 0, label.frame.size.width, label.frame.size.width) ;
view.layer.cornerRadius = view.frame.size.height/2;
view.layer.borderColor = [UIColor whiteColor].CGColor;
view.layer.borderWidth = 2.0;
view.clipsToBounds = true;
[view addSubview:label];
for (UIView *view in [annotationView subviews])
{
[view removeFromSuperview];
}
[annotationView addSubview:view];
annotationView.enabled = YES;
annotationView.annotation = annotation;
annotationView.canShowCallout = YES;
annotationView.pinTintColor = [UIColor clearColor];
} else {
annotationView.pinTintColor = [UIColor clearColor];
annotationView.layer.borderColor = [UIColor clearColor].CGColor;
annotationView.layer.borderWidth = 0.0;
FBAnnotation *a = (FBAnnotation*)annotation;
NSLog(#"amount is %f",a.amount);
UIImage *image = [UIImage imageNamed:#"icon-marker-select"];
UIImageView *imgView = [[UIImageView alloc]init];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
formatter.maximumFractionDigits = 2;
NSString *result = [formatter stringFromNumber:[NSNumber numberWithDouble:a.amount]];
NSString *strData = [NSString stringWithFormat:#"%#%#",a.currency,result];
UIFont *font = [UIFont fontWithName:#"Avenir-Medium" size:14.0];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.alignment = NSTextAlignmentCenter;
NSDictionary *attributes = #{
NSFontAttributeName : font,
NSParagraphStyleAttributeName : paragraphStyle,
NSForegroundColorAttributeName : [UIColor whiteColor]
};
CGSize textSize = [strData sizeWithAttributes:attributes];
CGRect textRect = CGRectMake(5, (image.size.height-textSize.height)/2 - 2, textSize.width , textSize.height);
UILabel *textLable = [[UILabel alloc]initWithFrame:textRect];
textLable.textColor = [UIColor whiteColor];
textLable.font = font;
textLable.text = strData;
UIImage *lightSymImg = [UIImage imageNamed:#"icon_lightning"];
UIImageView *lightImage = [[UIImageView alloc]init];
lightImage.image = lightSymImg;
CGRect imgRect = CGRectMake(textRect.origin.x+textRect.size.width, (image.size.height-lightSymImg.size.height)/2 - 2, lightSymImg.size.width,lightSymImg.size.height);
lightImage.frame = imgRect;
imgView.frame = CGRectMake(0, 0, imgRect.size.width + imgRect.origin.x+5, image.size.height);
imgView.image = image;
for (UIView *view in [annotationView subviews])
{
[view removeFromSuperview];
}
annotationView.annotation = annotation;
[annotationView addSubview:imgView];
[annotationView addSubview:textLable];
[annotationView addSubview:lightImage];
annotationView.enabled = YES;
annotationView.canShowCallout = NO;
}
return annotationView;
}
And in didSelect method i have written this code for Present a view Controller
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
NSLog(#"didSelectAnnotationView");
if ([view.annotation isKindOfClass:[FBAnnotationCluster class]]) {
NSLog(#"FBAnnotationCluster select annotation");
}
else{
SpotDetailVC *locDetailVC = [[UIStoryboard storyboardWithName:#"SpotDetail" bundle:nil] instantiateViewControllerWithIdentifier:#"SpotDetailVC"];
[self presentViewController:navController animated:YES completion:nil];
}
}
Now When i click on annotation for the first Time it works but after dismiss that view again click on Same annotation it does not works.
Please help, i know it's Silly mistake but i am not able to configure out that one.

Related

UITextField will not become first responder when touched, none of the usual mistakes apply

I have a UITextField that will not become the first responder when tapped. I can assign it to become first responder, which works find. But if it resigns first responder status and I try and tap it or tab back to it to make it become the first responder again, nothing happens. It appears as if the touch is being trapped somewhere, and yet I can't find anything in my code that could be causing that to happen. I've checked the usual suspects:
If the textfield the top view
is the textfield within the bounds of it's superview
is the textfield userEnabled.
I've also rewritten the code in several different ways, to no avail.
Can anyone help me with this problem. The textField at issue is the field titled answerTextField in the method createOneDoubleViewAtOrigin.
The relevant code is below.
-(instancetype)initForProblem:(NSString *)problem{
NSLog(#"%# '%#'",self.class, NSStringFromSelector(_cmd));
self = [super init];
if (self) {
[self parseBasicFractionProblem:problem];
if (_problemType == fractDoubleWithPic) {
NSLog(#"placed the fract views");
UIView *firstProblemView = [self createOneDoubleViewAtOrigin:CGPointMake(26, 30) withNumerator:_numerator1 denominator:_denominator1 forViewNumber:0];
UIView *secondProblemView = [self createOneDoubleViewAtOrigin:CGPointMake(342,30) withNumerator:_numerator2 denominator:_denominator2 forViewNumber:1];
[self addSubview:firstProblemView];
[self addSubview:secondProblemView];
[self bringSubviewToFront:firstProblemView];
[self bringSubviewToFront:secondProblemView];
}
else if (_problemType == fractDoubleNoPicAns||_problemType == fractDoubleNoPicExtendedAns ){
}
}
self.tag = 800;
self.backgroundColor = [UIColor redColor];
NSLog(#"made to end");
return self;
}
-(UIView *)createOneDoubleViewAtOrigin:(CGPoint)viewOrigin withNumerator:(NSInteger)numerator denominator:(NSInteger)denominator forViewNumber:(NSInteger)viewNumber{
NSLog(#"%# '%#'",self.class, NSStringFromSelector(_cmd));
UIView *containerView = [[UIView alloc] initWithFrame: CGRectMake(viewOrigin.x,viewOrigin.y, 310, 263)];
containerView.backgroundColor = [UIColor colorWithRed:178.0/255.0 green:222.0/255.0 blue:80.0/255.0 alpha:1.0];
containerView.layer.cornerRadius = 5.0;
UILabel *numeratorView = [self createSubview:CGRectMake(66, 23, 59, 47) text:[NSString stringWithFormat:#"%ld",(long)numerator] inView:containerView];
UILabel *divisorView = [self createSubview:CGRectMake(66, 40, 59, 47) text:#"___" inView:containerView];
UILabel *denominatorView = [self createSubview:CGRectMake(72, 82, 47, 47) text:[NSString stringWithFormat:#"%ld",(long)denominator] inView:containerView];
UILabel *equals = [self createSubview:CGRectMake(125, 50, 47, 47) text:#"=" inView:containerView];
/*
FFractSupportedTextField *answerField = [self createAnswerField:CGRectMake(173,50,82,47)];
*/
UITextField *answerTextField = [[UITextField alloc] initWithFrame:CGRectMake(173,50,82,47)];
//Inside
answerTextField.font = [UIFont fontWithName:#"Helvetica" size:30.0];
answerTextField.textAlignment = NSTextAlignmentCenter;
answerTextField.placeholder = #"?";
//border
answerTextField.layer.borderWidth = 1;
answerTextField.layer.borderColor = [[UIColor blackColor] CGColor];
answerTextField.layer.cornerRadius = 5.0;
answerTextField.userInteractionEnabled = YES;
[answerTextField addTarget:self action:#selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
containerView.tag = 820 + 6*viewNumber;
numeratorView.tag = 821 + 6*viewNumber;
divisorView.tag = 822 + 6*viewNumber;
denominatorView.tag = 823 + 6*viewNumber;
equals.tag = 824 + 6*viewNumber;
answerTextField.tag = 801 + viewNumber;
UIView *pictureView = [self createFractPictureForNumerator:numerator denominator:denominator number:viewNumber];
pictureView.tag = 825 + 6*viewNumber;
if (viewNumber == 0){
_answerTextField1 = answerTextField;
[containerView addSubview:_answerTextField1];
[containerView bringSubviewToFront:_answerTextField1];
_pictureView1 = pictureView;
[containerView addSubview:_pictureView1];
[_answerTextField1 becomeFirstResponder];
} else if (viewNumber == 1) {
_answerTextField2 = answerTextField;
[containerView addSubview:_answerTextField2];
[containerView bringSubviewToFront:_answerTextField2];
_pictureView2 = pictureView;
[containerView addSubview:_pictureView2];
}
return containerView;
}
-(UILabel *)createSubview:(CGRect)frame text:(NSString *)text inView:(UIView *)containerView{
NSLog(#"%# '%#'",self.class, NSStringFromSelector(_cmd));
UILabel *labelView = [[UILabel alloc] initWithFrame:frame];
labelView.font = [UIFont fontWithName:#"Helvetica" size:30.0];
labelView.textAlignment = NSTextAlignmentCenter;
labelView.text = text;
[containerView addSubview:labelView];
return labelView;
}
-(FFractSupportedTextField *)createAnswerField:(CGRect)frame{
NSLog(#"%# '%#'",self.class, NSStringFromSelector(_cmd));
FFractSupportedTextField *fieldView = [[FFractSupportedTextField alloc] initWithFrame:frame];
//Inside
fieldView.font = [UIFont fontWithName:#"Helvetica" size:30.0];
fieldView.textAlignment = NSTextAlignmentCenter;
fieldView.placeholder = #"?";
//border
fieldView.layer.borderWidth = 1;
fieldView.layer.borderColor = [[UIColor blackColor] CGColor];
fieldView.layer.cornerRadius = 5.0;
fieldView.userInteractionEnabled = YES;
return fieldView;
}
-(UIView *)createFractPictureForNumerator:(NSInteger)numerator denominator:(NSInteger)denominator number:(NSInteger)viewNumber{
NSLog(#"%# '%#'",self.class, NSStringFromSelector(_cmd));
NSLog(#"numerator:%ld denominator:%ld",(long)numerator,(long)denominator);
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(33, 165, 256, 78)];
containerView.backgroundColor = [UIColor whiteColor];
containerView.layer.borderColor = [[UIColor lightGrayColor] CGColor];
containerView.layer.borderWidth = 1.0;
containerView.layer.cornerRadius = 3.0;
NSInteger smallViewCount = denominator;
if (denominator == 0) {
smallViewCount = 1;
}
float smallWidth = 245.0/smallViewCount;
for (int n = 0; n < smallViewCount; n++) {
NSLog(#"count %d",n);
UILabel *smallLabel = [[UILabel alloc] initWithFrame:CGRectMake(8 + n*smallWidth, 8, smallWidth - 5, 29)];
smallLabel.backgroundColor = [UIColor colorWithRed:195.0/255.0 green:222.0/255.0 blue:172.0/255.0 alpha:1.0];
smallLabel.font = [UIFont fontWithName:#"Helvetica" size:17.0];
[smallLabel setAdjustsFontSizeToFitWidth:YES];
smallLabel.textAlignment = NSTextAlignmentCenter;
smallLabel.layer.cornerRadius = 3.0;
smallLabel.tag = 830+n + viewNumber*10;
[containerView addSubview:smallLabel];
}
UILabel *largeLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 41, 240, 29)];
largeLabel.backgroundColor = [UIColor colorWithRed:195.0/255.0 green:222.0/255.0 blue:172.0/255.0 alpha:1.0];
largeLabel.text = [NSString stringWithFormat:#"= %ld",(long)numerator];
largeLabel.textAlignment = NSTextAlignmentCenter;
largeLabel.layer.cornerRadius = 3.0;
[containerView addSubview:largeLabel];
NSLog(#"end of createFractPictFor..");
return containerView;
}

Current Location SKPulseAnimation does not work

I am doing one function, when users pressed a button, map will indicate users' current location by on pulse animation annotation.
SKCoordinateRegion region;
region.center = CLLocationCoordinate2DMake(_currentLocation.coordinate.latitude, _currentLocation.coordinate.longitude);
region.zoomLevel = 14;
self.mapView.visibleRegion = region;
SKAnnotation *CurrentLocationAnnotation = [SKAnnotation annotation];
CurrentLocationAnnotation.identifier = 1;
//CurrentLocationAnnotation.annotationType = SKAnnotationTypeMarker;
CurrentLocationAnnotation.location = CLLocationCoordinate2DMake(_currentLocation.coordinate.latitude, _currentLocation.coordinate.longitude);
SKAnimationSettings *CurrentLocationanimationSettings = [SKAnimationSettings animationSettings];
CurrentLocationanimationSettings.animationType = SKPulseAnimation;
CurrentLocationanimationSettings.animationEasingType = SKAnimationEaseLinear;
CurrentLocationanimationSettings.duration = 7000;
[self.mapView addAnnotation:CurrentLocationAnnotation withAnimationSettings:CurrentLocationanimationSettings];
I tried it on simulator and iphone as well, both of them don't work at all.
How can i fix it? thanks in advance
CLLocationCoordinate2D cordinate;
- (void)viewDidLoad {
[super viewDidLoad];
self.mapview.delegate=self;
self.locationManager.delegate = self
self.locationManager.distanceFilter = kCLDistanceFilterNone
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
[self.mapview setMapType:MKMapTypeSatellite];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 54, 122, 21)];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.3];
label.text = #"title";
//create our view for the image
UIImageView *coloredView1 = [[UIImageView alloc]initWithFrame:CGRectMake(7, 5.5, 122, 75)];
coloredView1.image = [UIImage imageNamed:#"demo.png"];
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(7, 5.5, 122, 75)];
view1.backgroundColor = [UIColor clearColor];
[view1 addSubview:label];
[view1 addSubview:coloredView1];
//create our view for the background image
UIImageView *coloredView2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0.0, 136, 110)];
coloredView2.image = [UIImage imageNamed:#"mapMarker"];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(7, 5.5, 122, 75)];
view1.backgroundColor = [UIColor clearColor];
[view2 addSubview:coloredView2];
[view2 addSubview:view1];
//create our view for the background image
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0.0, 136, 200)];
view3.backgroundColor = [UIColor clearColor];
[view3 addSubview:view2];
SKAnnotationView *annotationView = [[SKAnnotationView alloc] initWithView:customAnnotationView reuseIdentifier:#"reusableIdentifier"];
SKAnnotation *annotation = [SKAnnotation annotation];
annotation.identifier = 123456;
annotation.location = region.center;
annotation.annotationView = annotationView;
[self.mapView addAnnotation:annotation withAnimationSettings:[SKAnimationSettings animationSettings]];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
static NSString *identifier = #"myAnnotation";
DraggableAnnotationView * annotationView = (DraggableAnnotationView *)[self.mapview dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annotationView)
{
annotationView = [[DraggableAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.image = [UIImage imageNamed:#"ic_map_pin.png"];
}
else
{
annotationView.annotation = annotation;
}
annotationView.delegate = self;
return annotationView;
}
if this code helpful for you then give your vote ... thank you

how to show multiple info window of GMS mapView?

I want to add multiple info windows to appear at the same time with out tapping on the marker .
How to implement this ?
Here is my code to add multiple markers and adding a infoWindow?
for (int i = 0 ; i < jsonDataDict.count; i ++) {
NSDictionary *newDict = [jsonDataDict objectAtIndex:i ];
double latitude = [[newDict valueForKey:#"lat"]doubleValue];
double longitute = [[newDict valueForKey:#"lng"]doubleValue];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(latitude, longitute);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
nameOfPlace = [newDict valueForKey:#"name"];
// distanceOfPlace = [newDict valueForKey:#"distance"];
marker.icon = [self image:[UIImage imageNamed:#"pinPopoye.png"] scaledToSize:CGSizeMake(75.0f, 60.0f)];
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.infoWindowAnchor = CGPointMake(1.1, 0.70);
marker.map = self.mapView;
[self.mapView setSelectedMarker:marker];
//[self mapView:self.mapView markerInfoWindow:marker];
}
}
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 25)];
customView.backgroundColor = [UIColor colorWithRed:71.0/255.0 green:65.0/255.0 blue:65.0/255.0 alpha:0.8];
customView.layer.cornerRadius = 5;
customView.layer.masksToBounds = YES;
nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 10)];
nameLabel.text = nameOfPlace;
nameLabel.textColor = [UIColor whiteColor];
nameLabel.textAlignment = NSTextAlignmentCenter;
nameLabel.font = [UIFont systemFontOfSize:8.0];
[customView addSubview:nameLabel];
distanceLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 12, 60, 10)];
distanceLabel.text = distanceOfPlace;
distanceLabel.textColor = [UIColor whiteColor];
distanceLabel.textAlignment = NSTextAlignmentCenter;
distanceLabel.font = [UIFont systemFontOfSize:8.0];
[customView addSubview:distanceLabel];
return customView;
}

Stop iCarousel labels from scrolling

All my labels, done button and back button are scrolling within my icarousel. Is there a way to stop them from moving with the swipe gesture or are they inherently fixed? Or is it a case of taking them out of the function all together?
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
GalleryImage* gi = [self.galleryItem.galleryImages objectAtIndex:index];
UIImageView* imageView = nil;
UILabel* positionLabel = nil;
//UILabel* titleLabel = nil;
UILabel* label = nil;
UIButton* doneButton = nil;
UIView* labelBackground = nil;
UIActivityIndicatorView * spinnerView = nil;
UILabel * errorMessage = nil;
UILabel* titleLabel = nil;
//create new view if no view is available for recycling
if (view == nil) {
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.carousel.frame.size.width, self.carousel.frame.size.height)] ;
// Image
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.carousel.frame.size.width, self.carousel.frame.size.height)] ;
imageView.contentMode = UIViewContentModeScaleAspectFit;// UIViewContentModeCenter;
imageView.tag = 1;
// Spiner
spinnerView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[spinnerView setFrame:imageView.frame];
spinnerView.tag = 11;
//Error message
errorMessage = [[UILabel alloc] initWithFrame:spinnerView.frame];
[errorMessage setTextAlignment:NSTextAlignmentCenter];
[errorMessage setTextColor:[UIColor whiteColor]];
errorMessage.font = [UIFont fontWithName:#"Helvetica-Bold" size: 14.0];
errorMessage.tag = 111;
[imageView addSubview:errorMessage];
[imageView addSubview:spinnerView];
[view addSubview:imageView];
// Position
positionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.carousel.frame.size.width, 30)] ;
positionLabel.backgroundColor = [UIColor clearColor];
positionLabel.textAlignment = NSTextAlignmentCenter;
positionLabel.lineBreakMode = NSLineBreakByWordWrapping;
positionLabel.numberOfLines=1;
positionLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size: 14.0];
positionLabel.textColor = [UIColor whiteColor];
positionLabel.tag = 2;
//if(UIInterfaceOrientationPortrait == self.interfaceOrientation)
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
// Title
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, self.carousel.frame.size.width - 20, 100)] ;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = NSTextAlignmentLeft;
titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
titleLabel.numberOfLines = 4;
titleLabel.font = [UIFont fontWithName:#"Georgia" size: 18.0];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.text = [NSString stringWithFormat:#"%# \n", self.galleryItem.title];
[view addSubview:titleLabel];
/*
* Manage carousel speed and deceleration rate for portrait mode
*/
//self.carousel.decelerationRate = 0.175f;
//self.carousel.scrollSpeed = 0.45f;
}
else if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
/*
* Manage carousel speed and deceleration rate for landscape mode
*/
//self.carousel.decelerationRate = 0.25f;
//self.carousel.scrollSpeed = 0.55f;
}
labelBackground = [[UIView alloc] initWithFrame:CGRectMake(0, self.carousel.frame.size.height - 160, self.carousel.frame.size.width , 160)] ;
CAGradientLayer *labelBackgroundGradient = [CAGradientLayer layer];
labelBackgroundGradient.frame = labelBackground.bounds;
labelBackgroundGradient.colors = [NSArray arrayWithObjects: (id)[[UIColor clearColor]CGColor],
(id)[[UIColor blackColor]CGColor],
nil
];
[labelBackground.layer insertSublayer:labelBackgroundGradient atIndex:0];
labelBackground.opaque = false;
labelBackground.tag = 5;
// Description
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake( 0.0f,
0.0f,
labelBackground.bounds.size.width - 20.0f,
labelBackground.bounds.size.height)] ;
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentLeft;
label.numberOfLines = 0;
label.font = [label.font fontWithSize:12];
label.textColor = [UIColor whiteColor];
label.text = gi.descriptionGalleryImage;
[label autoAdjustGalleryCaptionSize];
[label setFrame:CGRectMake( label.bounds.origin.x + 10.0f,
label.bounds.origin.y + (labelBackground.bounds.size.height - (label.bounds.size.height + 10.0f)),
label.bounds.size.width,
label.bounds.size.height
)];
label.tag = 6;
[labelBackground addSubview:label];
[view addSubview:labelBackground];
} else {
imageView = (UIImageView *)[view viewWithTag:1];
spinnerView = (UIActivityIndicatorView*)[imageView viewWithTag:11];
errorMessage = (UILabel*) [imageView viewWithTag:111];
positionLabel = (UILabel *)[view viewWithTag:2];
doneButton = (UIButton *)[view viewWithTag:3];
//titleLabel = (UILabel *)[view viewWithTag:4];
labelBackground = (UIView *)[view viewWithTag:5];
label = (UILabel*)[view viewWithTag:6];
}
//Start image loading
ImageSize* imSize = [gi getLargestImage];
[spinnerView startAnimating];
errorMessage.text = #"";
[imageView sd_setImageWithURL:[NSURL URLWithString:imSize.source] placeholderImage:nil options:SDWebImageContinueInBackground progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//progress bar could be here
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//remove progressbar
[spinnerView stopAnimating];
//Display error message
if(error)
{
//errorMessage.text = error.localizedDescription;
errorMessage.text = #"Cannot load image";
}
//Assign image
if(image)
{
[imageView setImage:image];
}
}];
positionLabel.text = [NSString stringWithFormat:#"%d of %ld", (index + 1), (long)[self.galleryItem.galleryImages count]];
UIView* v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.carousel.frame.size.width, 30)];
v.backgroundColor = [UIColor blackColor];
v.alpha = 0.6;
[view addSubview:v];
[view addSubview:positionLabel];
// Done button
doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 0 , 50, 30);
[doneButton setImage:[UIImage imageNamed:#"back_button_white"] forState:UIControlStateNormal];
doneButton.imageEdgeInsets = UIEdgeInsetsMake(0,5,0,5);
[doneButton setTintColor:[UIColor whiteColor]];
[doneButton addTarget:self action:#selector(back) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:doneButton];
/*
* The description. Why are we setting the frame for the label multiple times?
* We need to do this so it can autoadjust its size and position according
* to the text contained within it.
*/
[label setText:gi.descriptionGalleryImage];
[label autoAdjustGalleryCaptionSize];
[label setFrame:CGRectMake( label.bounds.origin.x + 10.0f,
label.bounds.origin.y + (labelBackground.bounds.size.height - (label.bounds.size.height + 10.0f)),
label.bounds.size.width,
label.bounds.size.height
)];
labelBackground.hidden = self.hideLandscapeDetails;
label.hidden = self.hideLandscapeDetails;
doneButton.hidden = self.hideLandscapeDetails;
positionLabel.hidden = self.hideLandscapeDetails;
v.hidden =self.hideLandscapeDetails;
titleLabel.hidden = self.hideLandscapeDetails;
self.tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(showHideInfo:)];
[view addGestureRecognizer:self.tap1];
// scroll portrait view to same index
if (self.delegate) {
[self.delegate setReturnIndex:self.carousel.currentItemIndex];
}
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:#"Image Gallery" // Event category (required)
action:#"Gallery Image Viewed" // Event action (required)
label:#"Picture swipe" // Event label
value:[NSNumber numberWithLong:(index + 1)]] build]]; // Event value
return view;
}
The label should be above the iCarousel to do what you want, not inside the views of the carousel.

How to improve UITableView scrolling performance? What I am I missing?

I know the basics, what not to do in cellForRowAtIndexPath:, that may cause scrolling performance to be hindered. And I believe I have followed those rules, which is why I have gotten this far. My UITableView is horrible at scrolling, does so very well, but there are times where it stutters for split seconds to seconds, noticeable when it starts to slow down a bit.
Without revealing too much of my code, what here am I doing that could be causing this. I think I have gone over everything and eliminated something that could be causing it, but the problem persists. I feel as if it is something that is obvious and I am overlooking. Help is tremendously appreciated.
Thank you.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = #"tweetCell";
TweetCell *cell = (TweetCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
NSDictionary *tweet = _tweets[indexPath.row];
NSString *username = tweet[#"username"];
CGFloat tweetHeight = [tweet[#"contentHeight"] floatValue];
cell.tweet.frame = ({
CGRect frame = cell.tweet.frame;
frame.size.height = tweetHeight + 2;
frame.origin.y = cell.bounds.size.height / 2 - frame.size.height / 2;
frame;
});
cell.tweet.attributedText = tweet[#"attributedText"];
cell.imageView.image = [_profilePhotos[username] valueForKey:#"image"];
cell.date.text = tweet[#"dateString"];
if (tweet[#"media"]) {
cell.tweetImage.image = tweet[#"media"];
cell.tweetImage.hidden = NO;
} else {
cell.tweetImage.image = nil;
cell.tweetImage.hidden = YES;
}
NSMutableAttributedString *attributedText = [tweet[#"attributedText"] mutableCopy];
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"useDynamicTextSize"]) {
UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
if (cell.tweet.font.pointSize != font.pointSize) {
cell.tweet.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:font.pointSize];
cell.username.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:font.pointSize];
cell.date.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:font.pointSize];
[attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:#"HelveticaNeue-Light" size:font.pointSize] range:NSMakeRange(0, attributedText.length)];
} else {
[attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:#"HelveticaNeue-Light" size:cell.tweet.font.pointSize] range:NSMakeRange(0, attributedText.length)];
}
} else {
[attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:#"HelveticaNeue-Light" size:17] range:NSMakeRange(0, attributedText.length)];
}
cell.tweet.attributedText = attributedText;
cell.username.adjustsFontSizeToFitWidth = YES;
NSString *color = [[NSUserDefaults standardUserDefaults] objectForKey:#"color"];
if ([color isEqualToString:#"automatic"]) {
color = ([[UIScreen mainScreen] brightness] <= .5) ? #"black" : #"white";
}
[cell.imageView.layer setMasksToBounds:YES];
[cell.imageView.layer setCornerRadius:5];
[cell.imageView.layer setBorderColor:[[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.55] CGColor]];
[cell.imageView.layer setBorderWidth:0.5];
[cell.tweetImage.layer setMasksToBounds:YES];
[cell.tweetImage.layer setCornerRadius:5];
[cell.tweetImage.layer setBorderColor:[[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.55] CGColor]];
[cell.tweetImage.layer setBorderWidth:0.65];
// [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:0.25];
// [UIView setAnimationDelegate:self];
if ([color isEqualToString: #"white"]) {
cell.tweet.textColor =[UIColor blackColor];
cell.date.textColor = [UIColor blackColor];
cell.username.textColor = [UIColor blackColor];
cell.backgroundColor = [UIColor whiteColor];
cell.tweet.linkTextAttributes = #{NSForegroundColorAttributeName:[UIColor blueColor]};
[tweet[#"attributedText"] addAttribute:NSForegroundColorAttributeName
value:[UIColor blackColor]
range:NSMakeRange(0, cell.tweet.attributedText.length)];
} else /*if ([color isEqualToString: #"black"])*/ {
cell.tweet.textColor = [UIColor whiteColor];
cell.date.textColor = [UIColor whiteColor];
cell.username.textColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor colorWithRed:52/255.0 green:52/255.0 blue:52/255.0 alpha:1];
cell.tweet.linkTextAttributes = #{NSForegroundColorAttributeName: [UIColor colorWithRed:0.66 green:0.82 blue:1 alpha:1]};
[tweet[#"attributedText"] addAttribute:NSForegroundColorAttributeName
value:[UIColor whiteColor]
range:NSMakeRange(0, cell.tweet.attributedText.length)];
}
// [UIView commitAnimations];
if (_retweets[_tweets[indexPath.row][#"id"]]) {
if ([color isEqualToString: #"white"]) {
cell.backgroundColor = [UIColor colorWithRed:0.945 green:0.945 blue:0.945 alpha:1];
} else if ([color isEqualToString: #"black"]) {
cell.backgroundColor = [UIColor colorWithRed:0.114 green:0.114 blue:0.114 alpha:1];
}
// cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width);
} else {
if ([color isEqualToString: #"white"]) {
[cell setBackgroundColor:[UIColor whiteColor]];
} else if ([color isEqualToString: #"black"]) {
cell.backgroundColor = [UIColor colorWithRed:52/255.0 green:52/255.0 blue:52/255.0 alpha:1];
}
// cell.separatorInset = UIEdgeInsetsMake(0, 80, 0, 0);
}
cell.tweet.tag = indexPath.row;
cell.tweetImage.userInteractionEnabled = YES;
cell.tweet.frame = ({
CGRect frame = cell.tweet.frame;
frame.size.height = tweetHeight + 2;
frame.origin.y = cell.bounds.size.height / 2 - frame.size.height / 2;
if (tweet[#"media"]) {
frame.size.width = 164;
} else {
frame.size.width = 224;
}
frame;
});
cell.tweet.delegate = self;
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(retweetTweet:)];
doubleTap.numberOfTapsRequired = 2;
[cell addGestureRecognizer:doubleTap];
[cell.tweet addGestureRecognizer:doubleTap];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(showImage:)];
tap.numberOfTapsRequired = 1;
[cell.tweetImage addGestureRecognizer:tap];
UITapGestureRecognizer *tapToViewProfile = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(viewProfile:)];
tap.numberOfTapsRequired = 1;
[cell.imageView setUserInteractionEnabled:YES];
[cell.imageView addGestureRecognizer:tapToViewProfile];
return cell;
}
TweetCell.m:
//
// TweetCell.m
// Khabara
//
// Created by Isa Ranjha on 3/26/14.
// Copyright (c) 2014 Isa Ranjha. All rights reserved.
//
#import "TweetCell.h"
#implementation TweetCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
//self.imageView.frame = CGRectMake(self.imageView.frame.origin.x,self.imageView.frame.origin.y,45,45);
self.imageView.frame = ({
CGRect frame = self.imageView.frame;
frame.size = CGSizeMake(48, 48);
frame.origin.y = self.bounds.size.height / 2 - frame.size.height / 2;
frame;
});
self.imageView.backgroundColor = [UIColor whiteColor];
}
- (void)awakeFromNib
{
//_tweet.numberOfLines = 0;
_tweet.textContainerInset = UIEdgeInsetsZero;
_tweet.canCancelContentTouches = YES;
// _tweet.autoresizingMask = (UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
Do not use the set layer corner radius on cell. It make the problem. Instead of this, you better create a frame .png image.

Resources