Is there a way to find out the height of the camera view only(not the picker view)? I need to know so I can centre the cross hairs on my overlay view vertically - screenshot below
As an option - you can create custom camera overlay view with all custom controls on positions you want and then set:
imagePickerController.cameraOverlayView = yourOverlayView;
imagePickerController.showsCameraControls = NO;
Source and more info: in this SO question
Related
I am developing an iOS app which uses google maps. I want the marker to stick to the centre of the screen while dragging map or changing camera position. I have implemented below code. It keeps the marker at the centre of the screen, but marker moves when we drag the map and the repositions to centre. I want it to stay at the centre of the screen without moving it.
- (void)mapView:(GMSMapView *)pMapView didChangeCameraPosition:(GMSCameraPosition *)position {
/* move draggable pin */
if (movingMarker) {
CLLocationCoordinate2D location = pMapView.camera.target;
[movingMarker setPosition:location];
return;
}
}
Thanks in advance!
Solution is simple! Just place image view on top of map view, make image view same size (put same constraints, or autoresizing), and set your pin image to image view, set .center contentMode to image view. That's it! You don't have to add a marker to the map view itself. If you want to get pin (map view center) coordinate, use mapView.projection.coordinate(for: CGPoint) of google maps, where you have to pass map view's center point. Good luck!
I have an app where i'm creating a views hierarchy where i have a mapview and a tableview. The mapview is under the tableview and is visible on the top when the table vertical offset is negative.
The Structure of the view is something like this:
Where the yellow is the map, the green on the top is a navigation bar and green at the bottom is the tableview.
When you scroll the table view the map should show the user location at the center of the visible portion of the map.
The problem i'm experiencing is that when i apply the parallax the map center is not the location i'm setting.
This is a screenshot from a sample project that i did to isolate the problem. The center coordinate is Buckingham Palace.
The orange square is a debug view that is at the center of the mapView (where the center coordinate should be). I'm sure that the parallax effect it's correct.
The structure of my view hierarchy regarding the mapView in the sample project is represented in the following image. The position of the views reflects the screenshot above.
The following code is used to set the frame.origin.y value of the mapContainerView. I'm using the mapContainerView to avoid to touch the frame of the mapView to perform the parallax effect. The mapView is a subview of the mapContainerView (at the begin I was using a translation on the mapView but i changed the code to try to isolate the cause of this problem)
self.mapViewContainer.frame = CGRectMake(0, self.currentY, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
if (!CGRectEqualToRect(self.mapViewContainer.bounds, self.mapView.bounds)) {
self.mapView.bounds = CGRectMake(0,
0,
CGRectGetWidth(self.mapViewContainer.bounds),
CGRectGetHeight(self.mapViewContainer.bounds));
self.mapView.center = CGPointMake(CGRectGetMidX(self.mapViewContainer.bounds),
CGRectGetMidY(self.mapViewContainer.bounds));
}
self.squareView.bounds = CGRectMake(0, 0, 22.0f, 22.0f);
self.squareView.center = CGPointMake(CGRectGetMidX(self.mapViewContainer.bounds),
CGRectGetMidY(self.mapViewContainer.bounds));
My guess is that the status bar is doing something to the mapView. If you look to the simulator screenshot you can notice how the center coordinate are exactly located at the center of the vertical space that goes from the status bar to the bottom of the mapView.
If i set the center of the coordinate in the viewDidLoad, after the creation of the map (when it's frame is CGRectZero) the center of the map is correctly in the center of the map.
If i change it later (for example with a timer that, to simulate the location update, sets the same map region that it is set in the viewDidLoad) the map view decide to change the center as showed above.
I can't find any method to disable or change this behaviour. Am I doing something wrong here? I'm working on a workaround but i'm curious to know if someone know what i'm missing here.
This is the code of the sample project i created to reproduce the problem in an isolate scenario. https://gist.github.com/lucabartoletti/a5f103cb74a3edb178d6
Some restriction i have.
The map must be big enough to cover the window frame
The status bar must be visible
Try this:
_mapView.delegate = self;
func mapView(mapView: MKMapView!, didUpdateUserLocation
userLocation: MKUserLocation!) {
mapView.centerCoordinate = userLocation.location.coordinate
}
I am easily rotating my UIView using CATransform3DMakeRotation but the problem is occurring when em adding a SubView after the rotation. It is adding it as rotated..
This is my view before the rotation
This is how i am rotating my UIView
aCustomView.layer.transform = CATransform3DMakeRotation(M_PI,0.0,1.0,0.0);
and after that em adding a custom Badge on it by this
JSCustomBadge *onlineUsersCountBadge = [JSCustomBadge customBadgeWithString:#"1"];
CGSize size = onlineUsersCountBadge.frame.size;
onlineUsersCountBadge.frame = CGRectMake(imageViewRect.origin.x+20, imageViewRect.size.height*0.3, size.width, size.height);
[aCustomView addSubview:onlineUsersCountBadge];
This is my view after rotation and added Subview
If I understood it well, you want the view to rotate but the badge to stay normal.
In my opinion, the best approach to this problem is to create an invisible subview containing all the elements (UIViews) you want to rotate (such as the background image). You then shouldn't apply the rotation to the full view, but only to that subview. Doing so, if you want to add an element which shouldn't be rotated, such as your badge, you add it to the main non-rotated view and not to the rotated subview.
I am using the following code to rotate my image view and it is working fine..but whenever I change the view and go back. my image view moves up and eventually goes off the screen.. Any ideas why? Thanks..
self.anchorImage.layer.anchorPoint = CGPointMake(1.0,0.0);
CGAffineTransform cgaRotateHr = CGAffineTransformMakeRotation(1);
[self.imageView setTransform:cgaRotateHr];
Editing a photo after it's been taken (moving and scaling it) works fine in my app with this line:
[imagePicker setAllowsEditing:YES];
But if I also use a cameraOverlayView, the editing mode doesn't work anymore. The screen comes up, but pan and pinch gestures don't make anything happen.
I'm using your average image picker controller:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
And I add a camera overlay view, created from a custom view controller's view:
CameraOverlayViewController *overlayController = [[CameraOverlayViewController alloc] init];
UIView *overlayView = overlayController.view;
[imagePicker setCameraOverlayView:overlayView];
In IB, that view is set up to enable user interaction and multiple touch, which allows it to zoom and focus while taking the picture. But once the picture is taken and it enters editing mode, you cannot pan or pinch to move or scale the photo.
What am I missing?
Does your overlay take up the entire space of the camera view? If so, touches are going to the overlay instead of the view below, even if you have a transparent background.
Add this method to your overlay view and it will ignore touches so that they are passed to the views below. (You are overriding a method of UIView that detects touches.)
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
return NO;
}
Note: as well as that fantastic tip, you may also want to use this piece of info, to remove your overlay view, at that stage: UIImagePicker cameraOverlayView appears on Retake screen