Я создаю приложение, которое использует GeoFencing. Мои методы didEnterRegion и didExitRegion вызываются так, как они должны, по-видимому, в правильном порядке, но не обновляют пользовательский интерфейс соответственно.сделалEnterRegion и didExitRegion анимация противоречивая
Что работает:
- Пользователь вводит регион
- didEnterRegion вызывается
- UI правильно обновляется в рамках этого метода
Что не работает:
- пользователя введите область
- Пользователь идет прямо из одного региона в другой
- didExitRegion называется
- обновления пользовательского интерфейса
- didEnterRegion называется
- NSLogs показывают, что все выполняется в правильном порядке
- UI не обновляется. Обновления пользовательского интерфейса, которые были сделаны в didExitRegion, остаются.
Мои методы:
Пользовательские функции для обновления метки (вызывается из didEnterRegion и didExitRegion):
-(void)updateCurrentLocationLabelAndImage:(NSString *)locationText subLocationText:(NSString *)subLocationText;
{
// Clear existing animations before we begin
[self.locationLabel.layer removeAllAnimations];
[self.subLocationLabel.layer removeAllAnimations];
[self.ovalImageView.layer removeAllAnimations];
if (![locationText isEqual:@""])
{
// Only animate if the text changes
if (![self.locationLabel.text isEqualToString:locationText])
{
// Update the ovalImageView
CGSize maxLabelSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width - (([UIScreen mainScreen].bounds.size.width * 0.0267) * 2)), 64); // maximum label size
float expectedLabelWidth = [locationText boundingRectWithSize:maxLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName:self.locationLabel.font } context:nil].size.width; // get expected width
CGFloat xValueForImage = ((([UIScreen mainScreen].bounds.size.width - expectedLabelWidth)/2) - 25); // Calcuate the x-coordinate for the ovalImageView
if (xValueForImage < 15)
{
xValueForImage = 15; // we don't want it to display off-screen
}
self.ovalImageViewLeadingConstraint.constant = xValueForImage;
[self.view setNeedsUpdateConstraints];
[self changeLabelText:self.subLocationLabel string:subLocationText];
// Update the subLocationLabel
[UIView animateWithDuration:.15 animations:^{
// Animate
self.locationLabel.alpha = 0;
self.ovalImageView.alpha = 1;
[self.view layoutIfNeeded]; // update the UI
}completion:^(BOOL finished) {
// Set the text
self.locationLabel.text = locationText;
self.locationLabel.adjustsFontSizeToFitWidth = YES;
[UIView animateWithDuration:.15 animations:^{
// Animate
self.locationLabel.alpha = 1;
}completion:^(BOOL finished) {
// Complete
}];
}];
}
} else if ([locationText isEqual:@""])
{
// Move it to the center
self.ovalImageViewLeadingConstraint.constant = (([UIScreen mainScreen].bounds.size.width/2) - 9); // Default center calculation for this image
[self.view setNeedsUpdateConstraints];
[self changeLabelText:self.subLocationLabel string:subLocationText]; // Update the subLocationLabel
[UIView animateWithDuration:.15 animations:^{
self.locationLabel.alpha = 0;
self.ovalImageView.alpha = 1;
[self.view layoutIfNeeded];
}completion:^(BOOL finished) {
// Complete
self.locationLabel.text = @"";
}];
}
}
Но метка остается неизменным, даже если он регистрирует правильный порядок исполнения и все выглядит отлично. Есть идеи? Я действительно застрял ..
Спасибо!
Откуда берутся журнал «Введенный регион работы ...»? –
Ваше событие ввода региона 2 отменяет значение сразу после выхода из области 1. Попробуйте просмотреть значения на две разные метки и проверьте .. –
@NaveenPrasadR Тестовая метка, которую я добавил, теперь задана правильно – Erik