how to move view from mapkit in xcode - ios

I use mapkit framework in my app and I want move in my app with code not finger.
I create mapView and 4 buttons (up - bottom - left - right) that these buttons doing these works (go to top - go to bottom - ...) with code.
important notice : my friends I want moving specific part view (for example my specific part has 320px width and 100px height)
So I want when click top button my part (320*100) of my map move to top...
please guide me...

If each button moves to a static position (and zoom) on the map then you can create a configuration something like:
each button has an associated MKMapRect / MKCoordinateSpan
when a button is tapped, get the associated area information
call setVisibleMapRect:animated: on the map view
Note that you don't really need to think in terms of top / bottom, just specify exactly what area the map view should be displaying following selection of each button.
Alternatively, if the zoom level never changes, you can use setCenterCoordinate:animated:. Let's take this option for an example and using CLLocation to make life easy:
Create an array containing your locations:
configArray = #[ topLocation, bottomLocation, .... ];
Create the buttons, and set the tag of each to the appropriate array index:
topButton.tag = 0;
bottomButton.tag = 1;
...
When a button is tapped, get the tag to get the location to update the map:
CLLocation *location = self.configArray[sender.tag];
[self.mapView setCenterCoordinate:location.coordinate animated:YES];

Related

Unable to Add UI elements on top of AGSMapView

I have an app that I'm trying to migrate from Google Maps to ArcGIS maps because I need to use the maps offline.
I'm using the ArcGIS iOS 100.6 SDK and am trying to place a UIbutton on top of AGSMapView. In the View Controller "MapView" and the UIButton are under "View". The UIbutton is not a subview of MapView. I also have three other elements that should overlay the map that I hide and unhide using "isHidden = true/false" and these cannot be displayed either. The app is written in Swift 4.2 and I'm using Xcode 10.3.
Here is the view in the view controller:
View
Safe Area
Btn Satellite Toggle (outlet name: "btnSatelliteToggle")
View Mark Location
View Verify Location
View Pic Detail
MapView
Constraints
This is the code where I show the map and try to add the button on top:
let viewMap = AGSMapView(frame: .zero)
viewMap.map = AGSMap(basemapType: .navigationVector,
latitude: currentLocation.latitude, longitude: currentLocation.longitude,
levelOfDetail: zoomLevel)
viewMap.graphicsOverlays.add(overlay)
viewMap.touchDelegate = self
view = viewMap
view.bringSubviewToFront(btnSatelliteToggle)
The map is displayed along with the graphics overlay, but I am unable to show any UI elements on top of the map. This works fine with Google maps, but not with ArcGIS maps.
How do I get these UI elements to be displayed on top of the AGSMapView generated map?
Thanks in advance for your help.
It appears your MapView is at the top of the view hierarchy and thus obscuring its sibling views.
Try rearranging the view hierarchy to place the MapView at the bottom:
View
Safe Area
MapView
Btn Satellite Toggle (outlet name: "btnSatelliteToggle")
View Mark Location
View Verify Location
View Pic Detail
Constraints
I actually just solved this. Here is the updated code that works:
viewMap.map = AGSMap(basemapType: .navigationVector,
latitude: currentLocation.latitude, longitude: currentLocation.longitude,
levelOfDetail: zoomLevel)
viewMap.graphicsOverlays.add(overlay)
viewMap.touchDelegate = self
I removed:
Setting AGSMapView(frame: .zero)
as this prevented the map from being displayed in MapView.
Also, by not setting a view (thus using the default view controller "view") all siblings are available for display and can be controlled via "isHidden."

How can I tap on a UICollectionView cell of a collection view in UIAutomation?

How can I tap on a UICollectionView cell of a collection view in UIAutomation?
I tried this
var iconsCollView = window.collectionViews()[0];
var iconRect = iconsCollView.cells()[0].rect();
var iconX = iconRect.origin.x/100;
var iconY = iconRect.origin.y/100;
iconsCollView.tapWithOptions({tapOffset:{x: iconX, y: iconY}});
but it taps another cell in the collection view, a wrong cell other than the cell I specified its offset.
Can you please help me? is there another way?
From the UIAElement class reference:
Your script should treat the rect object as a generic JavaScript object whose properties for origin, x, y, size, width, and height correspond to those of the analogous CGRect Cocoa structure. The rect object has the form {origin:{x:xposition,y:yposition}, size:{width:widthvalue, height:heightvalue}}. The relevant coordinates are screen-relative and are adjusted to account for device orientation.
From the same source under tapWithOptions method:
You can use offsets to achieve finer precision in specifying the hitpoint within the rect for the specified element. The offset comprises a pair of x and y values, each ranging from 0.0 to 1.0. These values represent, respectively, relative horizontal and vertical positions within the rect, with {x:0.0, y:0.0} as the top left and {x:1.0, y:1.0} as the bottom right. Thus, {x:0.3, y:0.6} specifies a position just below and to the left of center, and {x:1.0, y:0.5} specifies a position centered vertically at the far right.
From the source you provided, you're trying to tap inside of collection view passing some weirdly scaled offset coordinates of one of its cells (instead of expected relative horizontal and vertical positions within the rect of collection view).
If you want to tap the cell simply locate it and call the tap method on it:
var iconsCollView = window.collectionViews()[0];
var iconCellToTap = iconsCollView.cells()[0].tap();

How to trace which image is currently seen in my Uiscrollview?

I am new to iOS.
I am working on UIScrollView based application. I have 3 images in UIScrollView.
I have 2 UIButtons which have selector method for Facebook and Twitter sharing.
I want to share image which is currently seen in UIScrollView to Facebook & Twitter.
I am stuck at extracting image at current scroll point.
After Googling I think something like UIPageController is the solution for me.
But I do not have any idea about how to implement it.
Please help me sort it out. Thank You!
I would say you have multiple options here, this is really a design question.
An easy (but also not very elegant) approach would be to fetch the current offset of the scroll view using its contentOffset property (depending on whether your scroll view scrolls horizontically or vertically, you have ease to use the x or y value of the contentOffset).
Next, you get the position values from your image views (again either myImageView.frame.origin.x or myImageView.frame.origin.y) and you can then calculate which of the image views is currently in the offset of the scroll view.
You can use a page controller (basically, you allow the user to end its scrolling on specific index).
Or when the user touches a button, you can retrieve the contentOffset of the scrollView and compare this value with the origin of the frame your images.
Assume, you created your images with these frames:
image1.frame = CGRectMake(0,0,320,250);
image2.frame = CGRectMake(0,250,320,250);
image3.frame = CGRectMake(0,500,320,250);
Now when you get the action:
-(IBAction)share:(id)sender {
CGPoint offset = self.scrollView.contentOffset;
if (offset.y < 250) {
//First image selected
}else if (offset.y > 500) {
//Third image selected
} else {
//Second image selected
}
}

How can I detect taps on a particular part (substring) of a UILabel?

I am new to iOS development. I dont know whether this questions has been asked already or not,
I tried searching for the solution on stackoverflow but didn't get any results.
Question :
I have a UILabel called myLabel with the text: "Click here to proceed"
Now the problem is I want to perform an action when user taps only "Click".
I know how to use UITapGestureRecognizer, but it responds to the whole UILabel. Is it possible to just detect when user taps only on string "Click"?
You could check the location of the touch to see if it is on the word "Click". This may not be completely accurate though and may break if you change the text in your label.
What you could do is first get the location of the click by using:
CGPoint location = [gesture locationInView:gesture.view];
This gets the location of the gesture in your view.
Once you have this, you can either have the size of the word "Click" hard-coded or you can create an identical label to your gesture label to get the size, such as:
UILabel *sizeLabel = //create label with same font.
[sizeLabel setText:#"Click"];
float width = [sizeLabel sizeThatFits:CGSizeMake(MAXFLOAT,MAXFLOAT)].width;
You could also do this when creating the actual label and store this width in a static variable so that you only have to do it once and you don't have to create an extra label (ie set the text of your real label to #"Click", get the width, and then set it to the real text).
Once you have the width, you and the location of the tap, you can check if the word "Click" was tapped by comparing:
if (location.x < width) {
//Put your tap code in here.
}

How do I move FPPopover as low as I want? If I push it too low, it jumps back to the top

I'm using FPPopover to present a pop over view for my iPhone app. I'm having an issue, however, where when I present it, it will only allow me to present it so low or it will jump to the top. And this is well before it gets cut off anyway.
For example:
[self.speedOptionsPopover presentPopoverFromPoint:CGPointMake(0, 235)];
Works fine, but if I put it a 255 instead of 235 (as it's a good 40px from the bottom) it jumps back up to the top.
Does anyone have any experience with this or how I could fix it?
Also, bonus points if you can explain why the content for the popover always starts like 50px from the top, when I want it to start up higher. How can I change this also?
More code from the creation:
- (void)speedOptionsTapped:(UIBarButtonItem *)sender {
// Set the delegate in the controller that acts as the popover's view to be self so that the controls on the popover can manipulate the WPM and number of words shown
self.speedOptionsController.delegate = self;
self.speedOptionsPopover.arrowDirection = FPPopoverNoArrow;
self.speedOptionsPopover.border = NO;
self.speedOptionsPopover.contentSize = CGSizeMake(320, 190);
[self.speedOptionsPopover presentPopoverFromPoint:CGPointMake(0, 235)];
}
Try replacing this part of the code in FPPopoverController.m:
//ok, will be vertical
if(ht == best_h || self.arrowDirection == FPPopoverArrowDirectionDown)
with this code:
//ok, will be vertical
if (self.arrowDirection == FPPopoverNoArrow)
{
r.origin.x = p.x;
r.origin.y = p.y;
}
else if(ht == best_h || self.arrowDirection == FPPopoverArrowDirectionDown)
The reason you might be having this issue is that the macro FPPopoverArrowDirectionIsVertical considers a popover with no arrows as having a vertical arrow. So, the result is that is tries to best position your popover as close as possible to the view that triggered the popover.
If you replace the code as indicated above, you'll be creating a special case for popovers with no arrows and asking that the original points be respected without repositioning.

Resources