How to check if Parallax is enabled

I am creating a wallpaper application and want to check if parallax is enabled on his iOS 7 device. Is there a way in objective-C that I can verify this? Did Apple Give Us Developers Access To This Bulleum?

i.e. if parallax is on, do step1, otherwise step2

+6
source share
3 answers

Starting with iOS 8:

// Returns whether the system preference for reduce motion is enabled UIKIT_EXTERN BOOL UIAccessibilityIsReduceMotionEnabled() NS_AVAILABLE_IOS(8_0); UIKIT_EXTERN NSString *const UIAccessibilityReduceMotionStatusDidChangeNotification NS_AVAILABLE_IOS(8_0); 

Anything earlier than iOS 8, I don’t think there is a legal way to say it.

+11
source

According to Gabriele's answer, there seems to be no way to directly read the value.

As a workaround, you can use the fact that UIInterpolatingMotionEffect does something if the movement is the default, but does nothing if the movement is allowed to decrease.

So, use a custom UIView class and attach an instance of UIInterpolatingMotionEffect right away when you start the application. Set the flag if the property is changed. Check out this flag later.

There may be some other empirical side effects you can rely on, but prima facie suggests that your user will move the device while using your application. Thus, you know for sure whether they have movement and moved their device, but otherwise you won’t know if the movement is turned off or you simply haven’t moved your device.

Maybe someone smarter can come up with something better?

EDIT: sample code. The issues encountered are addressed in the comments: the property must be animated, which has the net effect of having to manually poll. Add an instance of this view somewhere in your application, ideally, at startup and so that it stays on the screen for the life of your application, provided, of course, your view manager hierarchy. Then view the parallaxHasOccurred property. It meets KVO requirements, or you can interview. As discussed, it can generate false negatives, but should never generate false positives.

 @interface PTParallaxTestView : UIView // this key is KVO compliant @property (nonatomic, assign) BOOL parallaxHasOccurred; @end @implementation PTParallaxTestView { CGPoint _basePosition; UIMotionEffectGroup *_effectGroup; } - (void)didMoveToSuperview { // cancel any detection loop we may have ongoing [NSObject cancelPreviousPerformRequestsWithTarget:self]; // if anything still in doubt and we're on a view then start the // detection loop if(!self.parallaxHasOccurred && self.superview) { // add motion effects if they're not already attached; attach both to the centre property if(!_effectGroup) { UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; horizontalMotionEffect.minimumRelativeValue = @(0); horizontalMotionEffect.maximumRelativeValue = @(100); UIInterpolatingMotionEffect *verticalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; verticalMotionEffect.minimumRelativeValue = @(0); verticalMotionEffect.maximumRelativeValue = @(100); _effectGroup = [[UIMotionEffectGroup alloc] init]; _effectGroup.motionEffects = @[verticalMotionEffect, horizontalMotionEffect]; [self addMotionEffect:_effectGroup]; } // kick off inspection in 0.1 seconds; we'll subsequently inspect // every 0.5 seconds [self performSelector:@selector(beginCheckingPresentationPosition) withObject:nil afterDelay:0.1]; } } - (void)beginCheckingPresentationPosition { // set the base position and do the first check in 0.5 seconds _basePosition = [[[self layer] presentationLayer] position]; [self performSelector:@selector(checkPresentationPosition) withObject:nil afterDelay:0.5]; } - (void)checkPresentationPosition { // quick note on presentationLayer: // // The property supplied to UIInterpolatingMotionEffect must be animatable. So we can't just create our own. // UIKit will then apply effects directly to the layer. Furthermore, the layer itself will act as if in a // perpetual animation so its properties won't directly be affected. We'll have to query the presentationLayer. // (and that also why we're pulling rather than using KVO or a suitable subclass to push) // CGPoint newPosition = [[[self layer] presentationLayer] position]; // if the position has changed since the original test then things are in motion if(fabs(newPosition.x - _basePosition.x) > 0.125 || fabs(newPosition.y - _basePosition.y) > 0.125) self.parallaxHasOccurred = YES; // check again in 0.5 seconds only if we don't already know the answer if(!self.parallaxHasOccurred) [self performSelector:@selector(checkPresentationPosition) withObject:nil afterDelay:0.5]; } @end 
+5
source

For devices that do not support parallax (for example, any iPhone model prior to iPhone 5), you can simply check the model and make sure that parallax is turned on.

For the device supporting it, you should programmatically check the availability parameter to restrict movement, but apparently there is no open API to check whether this option is enabled.

According to the UIKit Feature Reference , the only checks you can perform are as follows

  • UIAccessibilityPostNotification
  • UIAccessibilityIsVoiceOverRunning
  • UIAccessibilityIsClosedCaptioningEnabled
  • UIAccessibilityRequestGuidedAccessSession
  • UIAccessibilityIsGuidedAccessEnabled
  • UIAccessibilityIsInvertColorsEnabled
  • UIAccessibilityIsMonoAudioEnabled
  • UIAccessibilityZoomFocusChanged
  • UIAccessibilityRegisterGestureConflictWithZoom
  • UIAccessibilityConvertFrameToScreenCoordinates
  • UIAccessibilityConvertPathToScreenCoordinates
+1
source

Source: https://habr.com/ru/post/959271/


All Articles