Small question, i've got a few annotations on a map view. Sometimes they tend to overlap when they are very close to each other and that's ok, but when i touch them they switch their layer position. Those that were in the back are now in the front and vice versa.
So i checked my didSelectAnnotation function but there is literarily no code in that function so it couldn't be it.
I couldn't think of anything else that might cause it.
Do you know how to fix it so it won't change layer position??
This is my viewForAnnotation code:
annImg = [[szAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"current"];
szPointAnnotation *pointAnnotation = annotation;
if (appDelegate.homePage || ([pointAnnotation.tag intValue] >= 10000))
{
annImg.canShowCallout = NO;
annImg.backgroundColor = [UIColor clearColor];
annImg.frame = CGRectMake(0, /*0*/-78, 70, /*78*/156);
UIImageView *currentUserPictureView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 60, 60)];
int newTag = [pointAnnotation.tag intValue]-10000;
UIImage *currentUserPicture;
if ([pointAnnotation.tag intValue] >= 10000) {
currentUserPicture = [UIImage imageWithData:[usersData getKeyForIndexWithKey:#"UserImageData" forIndex:newTag]];
}else{
currentUserPicture = [UIImage imageWithData:[usersData getKeyForIndexWithKey:#"UserImageData" forIndex:[pointAnnotation.tag intValue]]];
}
currentUserPictureView.image = currentUserPicture;
userLocationButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 70, 78)];
[userLocationButton setBackgroundImage:[UIImage imageNamed:#"pin.png"] forState:UIControlStateNormal];
[userLocationButton addTarget:self action:#selector(centerOnUser:) forControlEvents:UIControlEventTouchUpInside];
if ([pointAnnotation.tag intValue] >= 10000) {
userLocationButton.tag = newTag;
}else{
userLocationButton.tag = [pointAnnotation.tag intValue];
}
[userLocationButton setBackgroundColor:[UIColor clearColor]];
[annImg addSubview:userLocationButton];
[userLocationButton addSubview:currentUserPictureView];
[userLocationButton release];
[currentUserPictureView release];
[currentUserPicture release];
}
Related
Every time you click on the create button 4 rows of images are created. I'm using this technique for the game mastermind. When you click on the clear button every imageview has to be set to nil, but now only the last created 4 imageviews are set to nil. Any help would be appreciated!
- (IBAction)create {
_imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(134, y, 30, 30)];
_imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(170, y, 30, 30)];
_imgView3 = [[UIImageView alloc] initWithFrame:CGRectMake(206, y, 30, 30)];
_imgView4 = [[UIImageView alloc] initWithFrame:CGRectMake(241, y, 30, 30)];
_imgView1.image = [UIImage imageNamed:[textfield_code objectAtIndex:0]];
_imgView2.image = [UIImage imageNamed:[textfield_code objectAtIndex:1]];
_imgView3.image = [UIImage imageNamed:[textfield_code objectAtIndex:2]];
_imgView4.image = [UIImage imageNamed:[textfield_code objectAtIndex:3]];
[self.view addSubview:_imgView1];
[self.view addSubview:_imgView2];
[self.view addSubview:_imgView3];
[self.view addSubview:_imgView4];
y += 41;
}
- (IBAction)clear {
[_imgView1 setImage:nil];
[_imgView2 setImage:nil];
[_imgView3 setImage:nil];
[_imgView4 setImage:nil];
}
enumerate the view's subviews
for(UIImageView *v in self.view.subviews) {
if([v isKindOfClass:[UIImageView class]) {
[v setImage:nil];
}
}
BUT this is 'dangerous' as it removes ANY image view there is. it'd be better to use tags too.
e.g.
define it as #define MyTag 100
and when will creating v.tag = MyTag
and then in the loop check it if(v.tag == MyTag)
I need to draw dynamic images on UIScrollView for this i use, MKHorizion menu (A subclass of Scroll view). Now i add Subview images on scrollview. Loop worked perfectly for adding subview on scrollview. Now in My parent class I need to touch scroll view for updated data. If i didn't touch then it is not showing updated data. Below is code
-(void) reloadData
{
[self deleteAlliTem];
self.itemCount = [dataSource numberOfImagesForMenu:self];
self.backgroundColor = [dataSource backgroundColorForImage:self];
UIFont *buttonFont = [UIFont boldSystemFontOfSize:15];
int buttonPadding = 0;
int tag = kButtonBaseTag;
int xPos = kLeftOffset;
for(int i = 0 ; i < self.itemCount; i ++)
{
NSLog(#"*************************************************************");
NSMutableDictionary *dictData=[dataSource horizMenuImage:self dictForItmeAtIndex:i];
NSString *title=[dictData valueForKey:#"name"] ? [dictData valueForKey:#"name"] : #"";
UIImage* imageItem= [UIImage imageWithData:[Base64 decode:[dictData valueForKey:#"img"]]];
int buttonWidth = 95;
UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setTitle:title forState:UIControlStateNormal];
customButton.titleLabel.font = buttonFont;
[customButton setBackgroundImage:[UIImage imageNamed:#"addFriendStrip.png"] forState:UIControlStateNormal];
[customButton setBackgroundImage:[UIImage imageNamed:#"addFriendStrip.png"] forState:UIControlStateSelected];
customButton.tag = tag++;
[customButton addTarget:self action:#selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
customButton.frame = CGRectMake(xPos, 70, buttonWidth + buttonPadding, 25);
customButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
customButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
customButton.titleEdgeInsets =UIEdgeInsetsMake(0, 10,0, 0);
customButton.titleLabel.font = [UIFont fontWithName:#"Overlock-Bold" size:16];
[customButton setTitleColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1] forState:UIControlStateNormal];
[customButton setTitleColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1] forState:UIControlStateSelected];
UIImageView* itemImageView = [[UIImageView alloc] initWithImage:imageItem];
itemImageView.tag = 200 + customButton.tag;
[itemImageView setFrame:CGRectMake(xPos, 0, buttonWidth + buttonPadding, 95)];
[self addSubview:itemImageView];
[itemImageView release];
itemImageView = nil;
[self addSubview:customButton];
xPos += buttonWidth;
xPos += buttonPadding;
if (i != self.itemCount-1){
xPos += 2.5; //5; // Richa
}
}
self.contentSize = CGSizeMake(xPos, 95);
NSLog(#"############################################################################ - %d",[[self subviews] count]);
[self scrollRectToVisible:CGRectMake(1, 0, self.frame.size.width, self.frame.size.height) animated:YES];
}
Please Help me to sort out this. Why do i needed to touch scroll view ? Do i need to override other methods ?
Did you check it is on main thread ? may be you are using GCD Queue thats why it is not updating till touch.
just try to bring your scrollview on top.I am not getting your question correctly ,but it may help.
Let me know if it is working or not..!!!
Happy Coding.!!!!
How does one create a dynamic thumbnail grid?
How is a grid created with thumbnails of images like the photo app on iphone?
How are these spaces arranged dynamically? e.g. adding and removing thumbnails.
this is my simple grid view app
- (void)viewDidAppear:(BOOL)animated {
[[Grid_ViewAppDelegate sharedAppDelegate] hideLoadingView];
temp = temp+1;
if (temp ==1){
NSLog(#"temp:%d",temp);
int n = 20; //Numbers of array;
NSArray *t = [[NSArray alloc] initWithObjects:#"calpie.gif",#"chrysler_electric.png",#"chrysler_fiat_cap.gif",#"cleanup.gif",#"ecylindri.gif",#"elect08.png",#"globe.gif",#"heat.gif",#"insur.gif"
,#"jobs.gif",#"office.gif",#"opec1.gif",#"orng_cap.gif",#"poll.gif",#"pollen.gif",#"purbar.gif",#"robinson.gif",#"robslink_cap.gif",#"scot_cap.gif",#"shoes.gif",nil];
myScrollView.contentSize = CGSizeMake(320, 460+n*2);
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 1;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
NSString *mxiURL = #"http://meta-x.com/biflash/images/";
int i =0,i1=0;
while(i<n){
int yy = 4 +i1*79;
for(int j=0; j<4;j++){
if (i>=n) break;
CGRect rect;
rect = CGRectMake(4+79*j, yy, 75, 75);
UIButton *button=[[UIButton alloc] initWithFrame:rect];
[button setFrame:rect];
NSString *nn = [mxiURL stringByAppendingString:[t objectAtIndex:i]];
UIImage *buttonImageNormal=[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: nn]]];
[button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
button.tag =i;
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside ];
//[self.view addSubview:button];
[myScrollView addSubview:button];
//[buttonImageNormal release];
[button release];
i++;
//
}
i1 = i1+1;
//i=i+4;
}
}
}
in AppDelegate
+ (Grid_ViewAppDelegate *)sharedAppDelegate
{
return (Grid_ViewAppDelegate *)[UIApplication sharedApplication].delegate;
}
- (void)showLoadingView
{
if (loadingView == nil)
{
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
loadingView.opaque = NO;
loadingView.backgroundColor = [UIColor grayColor];
loadingView.alpha = 0.5;
UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(142.0, 222.0, 37.0, 37.0)];
[spinningWheel startAnimating];
spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loadingView addSubview:spinningWheel];
[spinningWheel release];
CGRect label = CGRectMake(142.0f, 255.0f, 71.0f, 20.0f);
lblLoading = [[UILabel alloc] initWithFrame:label];
lblLoading.textColor = [UIColor whiteColor];
lblLoading.font = [UIFont boldSystemFontOfSize:14];
// UILabel
lblLoading.backgroundColor =[UIColor clearColor];
[lblLoading setText:#"Loading..."];
//[lblLoading setTextAlignment:UITextAlignmentCenter];
[loadingView addSubview:lblLoading];
}
[window addSubview:loadingView];
}
- (void)hideLoadingView
{
[loadingView removeFromSuperview];
}
definitely if u apply this logic. u get succeed
I am enclosing my sample code herewith for ready reference, please make it in center place, this is what I am facing problem in. It is not stopping on the center indicator.
Note : All button are dynamic and coming from web, but in this sample I made it from a hard coded array. But in original scenerio their count(number of buttons) may change.
- (void)viewDidLoad {
arr = [[NSMutableArray alloc] initWithObjects:#"Test1",#"Test2",#"Test3",#"Test4",#"Test5",nil];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bg_content_slide.png"]];
img.frame = CGRectMake(0, 20, 320, 85);
img.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:img];
[self setScrollButtons];
[super viewDidLoad];
}
- (void) setScrollButtons
{
UIScrollView *tagScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, 320, 44)];
tagScrollView.backgroundColor = [UIColor clearColor];
[tagScrollView setShowsHorizontalScrollIndicator:NO];
[tagScrollView setShowsVerticalScrollIndicator:NO];
[tagScrollView setCanCancelContentTouches:NO];
tagScrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
tagScrollView.clipsToBounds = YES;
tagScrollView.scrollEnabled = YES;
tagScrollView.pagingEnabled = YES;
tagScrollView.bounces = YES;
tagScrollView.tag = 2;
int xaxis = 0;
for (int i = 0; i < [arr count]; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(xaxis, 0, 160, 44);
//btn.titleLabel.text = [NSString stringWithFormat:#"%#",[arr objectAtIndex:i]];
[btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
NSLog(#"%#", btn.titleLabel.text);
xaxis += btn.frame.size.width + 20;
[tagScrollView addSubview:btn];
}
[tagScrollView setContentSize:CGSizeMake([arr count] * 200, tagScrollView.frame.size.height)];
[self.view addSubview:tagScrollView];
}
Find code here UnAligned scrollview code
chage ur code with this one
int xaxis = 0;
for (int i = 0; i < [arr count]; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(320*xaxis+80, 0, 160, 44);
//btn.titleLabel.text = [NSString stringWithFormat:#"%#",[arr objectAtIndex:i]];
[btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
//[btn setBackgroundImage:[UIImage imageNamed:#"remove_fav.png"] forState:UIControlStateNormal];
NSLog(#"%#", btn.titleLabel.text);
xaxis ++;//= btn.frame.size.width + 40;
[tagScrollView addSubview:btn];
}
[tagScrollView setContentSize:CGSizeMake([arr count] * 320, tagScrollView.frame.size.height)];
[self.view addSubview:tagScrollView];
it will solve ur problem
What you want to achieve is not possible when pagination is enabled as when pagination is enabled the scroll view scroll to its width.So for this what you can do max is add this method
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGPoint offset = scrollView.contentOffset;
int temp = floor(offset.x/160);
[tagScrollView scrollRectToVisible:CGRectMake(temp*160, 0, 320, 44) animated:YES];
}
its working fine for this configuration .......
{
int xaxis = 0;
for (int i = 0; i < [arr count]; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(160*xaxis+85, 0, 150, 44);
[btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
NSLog(#"%#", btn.titleLabel.text);
xaxis ++;//= btn.frame.size.width + 40;
[tagScrollView addSubview:btn];
}
[tagScrollView setContentSize:CGSizeMake(160*xaxis+250, tagScrollView.frame.size.height)];
}
and .....
tagScrollView.pagingEnabled = NO;
Have a problem where my Label is not appearing. But the slider does. Its one of these bizarre cases that seems there is no logical reason. Anybody able to make sense of this?
else if (indexPath.row == 4)
{
Filters *filters = [Filters sharedInstance];
CGRect frame = CGRectMake(100, 10, 80, 23);
costSlider = [[[UISlider alloc] initWithFrame:frame] autorelease];
costSlider.maximumValue = [[NSNumber numberWithDouble:
filters.maxCarRentalCost] floatValue];
costSlider.minimumValue = [[NSNumber numberWithDouble:
filters.minCarRentalCost] floatValue];
[costSlider addTarget:self action:#selector(costSliderChanged:)
forControlEvents:UIControlEventValueChanged];
[costSlider setValue:[filters.maxCarCostPerDay floatValue] animated:YES ];
costSlider.continuous = NO;
costSlider.enabled = YES;
costSlider.value = [filters.maxCarCostPerDay floatValue];
costSlider.tag = 5;
[cell addSubview:costSlider];
self.costLabel.textColor = [UIColor greenColor];
self.costLabel.text = #"what"; //[NSString stringWithFormat:#"Cost per day:
%d", filters.maxCarCostPerDay ];
[self.costLabel setBackgroundColor:[UIColor blueColor]];
self.costLabel.frame = CGRectMake(10, 10, 75, 20);
[self.costLabel setFont:[UIFont boldSystemFontOfSize:10.0]];
[cell addSubview:self.costLabel];
}
Thanks
-Code
From the code you posted it does not look like you have alloc'd the label. Unless you are doing that elsewhere in the code, that is probably your issue