iOS6 MKMapView Zoom - ios6

I'm trying to get my MKMapView to zoom into to an annotation. I've tried all sorts however I remain zoomed out to my region.
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
NSLog(#"Did add annotations");
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
MKCoordinateSpan span;
span.longitudeDelta = 0.02;
span.latitudeDelta = 0.02;
MKCoordinateRegion region;
region.center = mapView.userLocation.coordinate;
region.span = span;
[mapView selectAnnotation:mp animated:YES];
[self.spotMapView setRegion:region animated:YES];
[self.spotMapView regionThatFits:region];
}
Which does run, however the map stays zoomed out.

Changing didAddAnnotationViews to this:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
NSLog(#"Did add annotations");
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
[mapView selectAnnotation:mp animated:NO];
}
Seemed to do the trick, the map now zooms in.

Related

Scnview nodes appear semi transparent

3D Perspective should block shelves etc correctly
Sample Image of the ScnView:
Very Simple. Added Scnview. Added Scnnodes ( shapes and lights )
Using standard Omni type light.
Why are the objects in front not blocking the objects behind ?
Here's the CODE:
[self.studioView addSubview:showTimeView];
showTimeView.frame = CGRectMake(self.paperView.frame.origin.x,
self.paperView.frame.origin.y,
self.paperView.frame.size.width,
self.paperView.frame.size.height);
SCNView *sceneView = (SCNView *)showTimeView;
sceneView.backgroundColor = [UIColor whiteColor];
sceneView.scene = [SCNScene scene];
SCNNode *root = sceneView.scene.rootNode;
sceneView.allowsCameraControl = YES;
sceneView.autoenablesDefaultLighting = NO;
// Add Camera
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
cameraNode.position = SCNVector3Make(0, 0, 100);
cameraNode.eulerAngles = SCNVector3Make(0, -M_PI/8, 0);
cameraNode.camera.zNear = 0;
cameraNode.camera.zFar = thisModuleDepth;
cameraNode.camera.xFov = thisWallWidth;
cameraNode.camera.yFov = thisModuleHeight;
[root addChildNode:cameraNode];
// Add Cabinet Piece
SCNBox *cubeGeom = [SCNBox boxWithWidth:tW
height:tH
length:tD
chamferRadius:0.0];
SCNNode *cubeNode = [SCNNode nodeWithGeometry:cubeGeom];
cubeNode.position = SCNVector3Make(tX, tY, tZ);
// Tag Material
SCNMaterial *material = [SCNMaterial material];
material.diffuse.contents = [UIImage imageNamed:thisColor];
[material.diffuse.contents setAccessibilityIdentifier:thisColor] ;
[material.diffuse.contents setAccessibilityLabel:thisID] ;
cubeNode.geometry.firstMaterial = material;
cubeNode.geometry.firstMaterial.locksAmbientWithDiffuse = NO;
cubeNode.physicsBody = [SCNPhysicsBody staticBody];
[root addChildNode:cubeNode];
// Add spotlight
SCNLight *spotLight = [SCNLight light];
spotLight.type = SCNLightTypeOmni;
spotLight.color = [UIColor whiteColor];
SCNNode *spotLightNode = [SCNNode node];
spotLightNode.light = spotLight;
spotLightNode.position = SCNVector3Make(thisWallWidth / 2 ,thisModuleHeight, thisModuleDepth *2);
spotLightNode.light.intensity = 1000;
[root addChildNode:spotLightNode];
Thanks Noah,
I finally figured out what was wrong!!!
Set the automaticallyAdjustsZRange property of your SCNCamera to true and it will ensure that nothing is clipped because of the wrong zNear or zFar being set.
THANKS FOR YOUR HELP !!!
HERE IT IS FIXED: Perfect 3D Perspective

UItextView dynamiclly Height and Link reconizer iOS 6 vs ios 7

I develop an application and I need to display the content using an UITextView which must have set the height dynamically and it must recognize a link.
I used code above:
self.textView.text = [NSString stringWithFormat:#"%# \n %#", self.offersObjects.body, self.offersObjects.url];
self.textView.dataDetectorTypes = UIDataDetectorTypeLink;
if (([[[UIDevice currentDevice] systemVersion] integerValue] < 7)){
CGRect frame = self.textView.frame;
frame.size.height = self.textView.contentSize.height;contentSize.height;
self.textView.frame = frame;
}else{
[self.textView sizeToFit];
[self.textView layoutIfNeeded];
}
My problem is that it doesn't recognize the link .
try with below code :
-(IBAction)txtStustes:(id)sender
{
NSError *error = nil;
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink
| NSTextCheckingTypePhoneNumber error:&error];
NSString *string = self.textView.text;
NSArray *matches = [detector matchesInString:string options:0 range:NSMakeRange(0, [string length])];
for (NSTextCheckingResult *match in matches) {
if ([match resultType] == NSTextCheckingTypeLink) {
NSURL *url = [match URL];
[[UIApplication sharedApplication] openURL:url];
}
}
}
Also add below code in your viewDidLoad method
UITapGestureRecognizer *LblProfileNameTouch=[[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(txtStustes:)];
[LblProfileNameTouch setNumberOfTouchesRequired:1];
[self.textView addGestureRecognizer:LblProfileNameTouch];

When and how is collectionView:viewForSupplementaryElementOfKind:atIndexPath: called?

I'm trying to implement a native-Calendar-app-like timeline view with UICollectionView and custom layout. And I'm new to it.
Here is where my problem come from.
I'm using Decoration View to implement those background gridlines, and trying to use Supplementary View to make the time labels (near the gridlines), and will use Cell to make the events but not that far yet.
But before doing the events, I found when I run it all the supplementary views are not working, no matter if I have cell or not. And I found my collectionView:viewForSupplementaryElementOfKind:atIndexPath: method is not called.
So I'm wondering how and when this method is called? What could be leading to my situation that it's not called?
Actually, is it good to make those time labels with supplementary view? I'm not sure about it since I do need them to be visible even when there's no event (no cell/item in section).
Here is my code:
View Controller
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.backgroundColor = [UIColor whiteColor];
[self.collectionView registerClass:TodayCellKindTask.class forCellWithReuseIdentifier:CellKindTaskIdentifier];
[self.collectionView registerClass:TodayTimelineTimeHeader.class forSupplementaryViewOfKind:TimelineKindTimeHeader withReuseIdentifier:TimelineTimeHeaderIdentifier];
[self.timelineViewLayout registerClass:TodayTimelineTileWhole.class forDecorationViewOfKind:TimelineKindTileWholeHour];
[self.timelineViewLayout registerClass:TodayTimelineTileHalf.class forDecorationViewOfKind:TimelineKindTileHalfHour];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 5;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
TodayCellKindTask *cellTask = [collectionView dequeueReusableCellWithReuseIdentifier:CellKindTaskIdentifier forIndexPath:indexPath];
return cellTask;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
NSLog(#"viewForSupplementaryElementOfKind");
TodayTimelineTimeHeader *timeHeader = [self.collectionView dequeueReusableSupplementaryViewOfKind:TimelineKindTimeHeader withReuseIdentifier:TimelineTimeHeaderIdentifier forIndexPath:indexPath];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *today = [NSDate date];
NSDateComponents *comps = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:today];
[comps setHour:indexPath.item];
timeHeader.time = [calendar dateFromComponents:comps];
return timeHeader;
}
Custom Layout
// in prepareLayout
NSMutableDictionary *timeHeaderAttributes = [NSMutableDictionary dictionary];
CGSize headerSize = [TodayTimelineTimeHeader defaultSize];
CGFloat headerOffsetY = (tileSize.height - headerSize.height) / 2;
for (NSInteger hour = 24; hour >= 0; hour--) {
NSIndexPath *timeHeaderIndexPath = [NSIndexPath indexPathForItem:hour inSection:0];
UICollectionViewLayoutAttributes *currentTimeHeaderAttributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:TimelineKindTimeHeader withIndexPath:timeHeaderIndexPath];
CGFloat headerPosY = hour * 2 * tileSize.height + headerOffsetY;
currentTimeHeaderAttributes.frame = CGRectMake(TimeHeaderPosX, headerPosY, headerSize.width, headerSize.height);
timeHeaderAttributes[timeHeaderIndexPath] = currentTimeHeaderAttributes;
}
self.timelineTileAttributes[TimelineKindTimeHeader] = timeHeaderAttributes;
// layoutAttributesForSupplementaryViewOfKind
- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
return self.timelineTileAttributes[kind][indexPath];
}
// layoutAttributesForElementsInRect
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSMutableArray *allAttributes = [NSMutableArray arrayWithCapacity:self.timelineTileAttributes.count];
[self.timelineTileAttributes enumerateKeysAndObjectsUsingBlock:^(NSString *elementIdentifier,
NSDictionary *elementsInfo,
BOOL *stop) {
[elementsInfo enumerateKeysAndObjectsUsingBlock:^(NSIndexPath *indexPath,
UICollectionViewLayoutAttributes *attributes,
BOOL *stop) {
if (CGRectIntersectsRect(rect, attributes.frame)) {
[allAttributes addObject:attributes];
}
}];
}];
return allAttributes;
}
// collectionViewContentSize
- (CGSize)collectionViewContentSize {
CGSize tileSize = [TodayTimelineTileWhole defaultSize];
CGFloat contentHeight = tileSize.height * self.numberOfTiles;
return CGSizeMake(tileSize.width, contentHeight);
}
I tried not to post all the code here since that'd be a lot, but let me know if you need to know others.
Any tip is appreciated!
Pine
So, this problem is solved, and the reason was my stupid mistake, setting those views' position x out of the screen, and due to that the method was not called. Nothing else.
I found this reason by logging out each view's frame in prepareLayout, and found the x position was wrong. I got this position from the retina design so…
I used supplementary view and it was working without any problem.
My lesson: no worries, calm down. This can save you time from making mistake.

UIPanGestureRecognizer and BringSubviewToFront

I have an app where the user taps a button and the app will instantiate an image layer (UIImageView). I want to make it so that the user can move the selected image layer whichever they tap. After reading some topics here, I've learnt that I can use UIPanGestureRecognizer to move the selected image layer.
- (IBAction)buttonClicked:(id)sender {
imageview = [[UIImageView alloc] initWithFrame:CGRectMake(100, 0, 300, 22)];
UIPanGestureRecognizer *imageviewGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(recognizePan:)];
[imageviewGesture setMinimumNumberOfTouches:1];
[imageviewGesture setMaximumNumberOfTouches:1];
imageview.image = [UIImage imageNamed:#"pinimage.png"];
[imageview addGestureRecognizer:imageviewGesture];
[imageview setUserInteractionEnabled:YES];
[self.view addSubview:imageview];
NSUInteger currentag = [self UniqueTag]; // Assigning a unique integer
imageview.tag = currentag;
}
- (void)recognizePan:(UIPanGestureRecognizer *)sender {
[[[(UITapGestureRecognizer *)sender view] layer] removeAllAnimations];
[self.view bringSubviewToFront:[(UIPanGestureRecognizer *)sender view]];
CGPoint translatedPoint = [(UIPanGestureRecognizer *)sender translationInView:self.view];
if([(UIPanGestureRecognizer *)sender state] == UIGestureRecognizerStateBegan) {
firstX = [[sender view] center].x;
firstY = [[sender view] center].y;
}
translatedPoint = CGPointMake(firstX + translatedPoint.x,firstY + translatedPoint.y);
[[sender view] setCenter:translatedPoint];
}
Now, what I cannot figure out is how to bring the tapped layer to front when there are multiple image layers. It doesn't seem that [self.view bringSubviewToFront:[(UIPanGestureRecognizer *)sender view]] is effective. So how can I revise my code so that the application will bring the tapped layer to the top among others?
Thank you for your help.
A good way to do this is to make a CustomImageView subclass of UIImageView. You attach the UIPanGestureRecognizer to each instance of CustomImageView, and set that instance as it's target. Then the action method triggered by the gesture is implemented in the view itself, so that you can refer to the view with self:
In buttonClicked
MyImageView* imageview = [[MyImageView alloc] initWithFrame:CGRectMake(100, 0, 300, 22)];
UIPanGestureRecognizer *imageviewGesture =
[[UIPanGestureRecognizer alloc] initWithTarget:imageview
action:#selector(recognizePan:)];
In CustomImageView.m
- (void)recognizePan:(UIPanGestureRecognizer *)sender {
[self.layer removeAllAnimations];
[self.superview bringSubviewToFront:self];
CGPoint translatedPoint = [sender translationInView:self];
if([sender state] == UIGestureRecognizerStateBegan) {
self.firstX = [self center].x;
self.firstY = [self center].y;
}
translatedPoint = CGPointMake(self.firstX + translatedPoint.x,
self.firstY + translatedPoint.y);
[self setCenter:translatedPoint];
}
update
Not thinking straight - you can of course do this from the viewController, as you are doing, by accessing the view property of the gestureRecongnizer. Your error is rather here:
- (void)recognizePan:(UIPanGestureRecognizer *)sender {
[[[(UITapGestureRecognizer *)sender view] layer] removeAllAnimations];
You are changing the sender type from UIPanGestureRecognizer to UITapGestureRecognizer. In fact you don't need to do any of that sender typecasting in the body of the method.

I have a UICollectionView and i want to show an image in a Cell, that goes to a normal ViewController. How do i do that?

I have a UICollectionViewController (with a navigation controller) and i want to show an image in a Cell that 'pushes' to a normal ViewController (different by every image). How do i do that?
Seem you want to build photo gallery by UICollectionView.
If use storyBoard, use segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"])
{
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
// load the image, to prevent it from being cached we use 'initWithContentsOfFile'
NSString *imageNameToLoad = [NSString stringWithFormat:#"%d_full", selectedIndexPath.row];
NSString *pathToImage = [[NSBundle mainBundle] pathForResource:imageNameToLoad ofType:#"JPG"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.image = image;
}
}
If use nib: inside didSelectItemAtIndexPath, use self.navigationController push.
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
NSString *imageNameToLoad = [NSString stringWithFormat:#"%d_full", indexPath.row];
NSString *pathToImage = [[NSBundle mainBundle] pathForResource:imageNameToLoad ofType:#"JPG"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
detailViewController.image = image;
[self.navigationController pushViewController:detailViewController animated:YES];
}
Sample code from Apple:
https://developer.apple.com/library/ios/#samplecode/CollectionView-Simple/Introduction/Intro.html
CollecionView tutorial: http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12

Resources