mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Display user heading in location picker and location view
This commit is contained in:
@@ -71,6 +71,8 @@
|
||||
bool _throttle;
|
||||
TGLocationPinAnnotationView *_ownLiveLocationView;
|
||||
__weak MKAnnotationView *_userLocationView;
|
||||
|
||||
UIImageView *_headingArrowView;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -162,6 +164,8 @@
|
||||
[_liveLocationsDisposable dispose];
|
||||
[_reloadDisposable dispose];
|
||||
[_frequentUpdatesDisposable dispose];
|
||||
|
||||
[_locationManager stopUpdatingHeading];
|
||||
}
|
||||
|
||||
- (void)tg_setRightBarButtonItem:(UIBarButtonItem *)barButtonItem action:(bool)action animated:(bool)animated {
|
||||
@@ -438,6 +442,36 @@
|
||||
{
|
||||
[super loadView];
|
||||
|
||||
static UIImage *headingArrowImage = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
|
||||
dispatch_once(&onceToken, ^
|
||||
{
|
||||
UIGraphicsBeginImageContextWithOptions(CGSizeMake(28.0f, 28.0f), false, 0.0f);
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
|
||||
CGContextClearRect(context, CGRectMake(0, 0, 28, 28));
|
||||
|
||||
CGContextSetFillColorWithColor(context, UIColorRGB(0x3393fe).CGColor);
|
||||
|
||||
CGContextMoveToPoint(context, 14, 0);
|
||||
CGContextAddLineToPoint(context, 19, 7);
|
||||
CGContextAddLineToPoint(context, 9, 7);
|
||||
CGContextClosePath(context);
|
||||
CGContextFillPath(context);
|
||||
|
||||
CGContextSetBlendMode(context, kCGBlendModeClear);
|
||||
CGContextFillEllipseInRect(context, CGRectMake(5.0, 5.0, 18.0, 18.0));
|
||||
|
||||
headingArrowImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
});
|
||||
|
||||
_headingArrowView = [[UIImageView alloc] init];
|
||||
_headingArrowView.hidden = true;
|
||||
_headingArrowView.frame = CGRectMake(0.0, 0.0, 28.0, 28.0);
|
||||
_headingArrowView.image = headingArrowImage;
|
||||
|
||||
_tableView.scrollsToTop = false;
|
||||
_mapView.tapEnabled = false;
|
||||
|
||||
@@ -495,6 +529,8 @@
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[_locationManager startUpdatingHeading];
|
||||
|
||||
if (self.previewMode && !animated)
|
||||
{
|
||||
UIView *contentView = [[_mapView subviews] firstObject];
|
||||
@@ -950,6 +986,9 @@
|
||||
{
|
||||
_userLocationView = view;
|
||||
|
||||
[_userLocationView addSubview:_headingArrowView];
|
||||
_headingArrowView.center = CGPointMake(view.frame.size.width / 2.0, view.frame.size.height / 2.0);
|
||||
|
||||
if (_ownLiveLocationView != nil)
|
||||
{
|
||||
[_userLocationView addSubview:_ownLiveLocationView];
|
||||
@@ -982,6 +1021,14 @@
|
||||
return CLLocationCoordinate2DMake(_locationAttachment.latitude, _locationAttachment.longitude);
|
||||
}
|
||||
|
||||
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
|
||||
{
|
||||
if (newHeading != nil) {
|
||||
_headingArrowView.hidden = false;
|
||||
_headingArrowView.transform = CGAffineTransformMakeRotation(newHeading.magneticHeading / 180.0 * M_PI);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
|
||||
Reference in New Issue
Block a user