There is a parallax effect at 5s. Parallax effect in iOS apps. Panoramic pictures at "simtsi"

Golovna / Google Play

Everyone knows that Apple is trying to figure out all the categories of its quirks and released such a function, like a change to the iPhone.

It’s more korisna and may be logically explained and stunned. Let's understand what it is and how it can be activated.

What is the change in ruhu in iOS?

I guess I may be that with the advent of iOS 7 there were a lot of changes, and one of them was a feature of the visual depth of the screen.

If you put a special standard trellis on your iPhone, then in Russia the stench will collapse and look even more effective.

The year also began to improve the animation of the programs. Also, animations of transitions and a lot of other things were improved.

If the coristuvachevi are simply not up to anything, then everything can be turned on for the additional function “Change of Rukh”. What is the same, to help protect the trochs of the battery charge.

Let's talk about turning on for a little while, but for now I want to re-enable it myself, after activation:

  • the animation is taken from the standard add-on "Weather";
  • all screen effects are changed again;
  • the parallax effect, which I explained for the espalier, is also included;
  • well, and other standard programs also cease to win animation.

I think you have understood the basic essence of this function, and now the time has come to proceed to the part, if we tell you about how to activate the function correctly or turn it on when needed.

How to turn off / turn off the change on the iPhone?

For some part of the fact that the most part of this function is found on old outbuildings or telephones, the battery of which has already changed in the system.


This means that you have to work to improve the performance of the iPhone and if you have an old model and you don’t want to smoothly build your robot on the rest of iOS.

Well, now you can proceed to the inclusion of the function of changing the movement:

  1. yak i zavzhdi, we go into Nalashtuvannya- Shukaemo item Main;
  2. go to Universal accessRukh change;
  3. Bachimo point with a similar name and just activate yoga, so that it turns green.


At the bottom, you could mark one more item, which is called "Effective repair (auto)". Naykrasche, shchob won zalishalas active.

If you turn it on, then in case of a bad day, if you have to force the effect on the kshtalt bag, the salute of those others, then the stench simply does not work.

I immediately squirm with iPhones 5S and I її activating, as if only switching to iOS 10. The back is loudly silent, but then it’s normal and pratsyuvati became more comfortable.

Apple uses high-performance components to reach the uncompromising firmware of the iPhone and iPad. However, software embellishments, animations and other neobov'yazkovy features of the operating system are negatively marked on the speed of robotic mobile devices. It is not the top gadgets themselves that are worth the trouble.

You can solve the problem by turning on the most resource-saving functions. Vikoristovuyuchi standard operating system, you can increase the productivity of old models of the iPhone and iPad.

Wimknut Search Spotlight

In 2009, heavenly manna sat on the heads of the coristuvachi iPhones. The third version of the iPhone OS was released, giving the apple phone a hundred new features. For the first time in Apple smartphones, such sounds appeared at once, such as "copy-copy-paste", MMS and the universal Spotlight search mechanism.

You can have a drink in the rest, swipe down to the beast on the be-yakіy side of the home screen. Spotlight is nothing else, like a global search for all content: contacts, mail, SMS, add-ons, music, calendar, and one of the main things - mittevity and accuracy of the result. The problem lies in the fact that Spotlight is constantly indexing mobile devices, so that you are aware of all changes in the OS. These functions allow you to access the upgrade of the firmware code of iPhone and iPad. Go to Settings -> General -> Search Spotlight and check the checkboxes for all the checkboxes.

Disable background software update

Apps in iOS 8 can pick up background mode information. The function is more corny, but it also shows the charge of the battery and adds to the processor fatigue. Go to the menu Adjustment –> Main –> Update content and turn off the use of services in the background. The function can be turned off again or it can be used to switch between different programs.

Reduce parallax and matte effect

Apple, singsongly, spent a lot of time creating a parallax effect for tapestries, which creates a three-dimensional effect. Seeing everything is beautiful, but the cream of the zayvogo on the processor, tsya mozhlivist no longer fit. Therefore, when trellises are fixed in iOS 8, the term “Perspective” is translated in the position of Wimk.

The special chic of Apple's software shell is due to the transparency effect. Lots of elements in iOS 8 with the effect of volume balls over the main interface. With this, everything that is lower, we grow apart, as if behind a matte fold. This effect is monitored in the OS everywhere, including the Reminder Center, the Care Center and the top panel with the Yearbook. You can change the UI transparency by going to the Adjust menu -> General -> Universal access -> Enhance contrast. Behind the zamovchuvannyam remikach Decreased visibility to stand at the position of "Wimk". With the inclusion of an effect, it works visually better, especially on not the latest models.

Turn on the animation

Apple has been creating a beautiful pseudo-trivial effect for a “flat” iOS interface for a long time: menus, icons, notifications, which can easily change your look when you are sickly attached. The function is to complete the insignificant, protege the processor hour. Therefore, let's go for the address Nalashtuvannya -> Basic -> Universal access and activate the item "Change of traffic".

Call for a place in memory

On the iPhone and iPad, you can also use the “tidy up” option. Show that you are working here in the office and after a certain hour you will note that your style is step by step beginning to be harassed by inappropriate documents and papers. What are you doing? That's right, you will bring cleanliness and order, so that you can make more money and work more effectively. Those are the same in iOS. Smartphones and tablets, like desktop computers, also need to be kept clean and in order.

You can find a list of installed programs, arrangements for the expansion of data, like stinks, you can in the settings of the operating system. For which one you want to split the Basics, go to the Statistics menu. iOS 8 will show the expansion of the program to allow you to quickly expand the memory on the extension.

In autumn, Apple announces public access to the mobile operating system iOS 7 with a revolutionary design and a great set of new features and software updates. The innovation will be just richer, starting from the rebuilt modern look and ending with a unique approach to usability. Until the rest, the titles of the paralax-effect, which, as it seems, rozrobniki, calls out, change the way that they coexist with mobile outbuildings.

Apple describes this technology as follows:

“iOS 7 creates a lot of richness. The operating system is the most advanced technology of the iPhone, iPad and iPod touch, to further expand the capabilities of iOS. Readings and functional balls create clay and arrange content.

Napіvprozore smolderingly gives an obvious connection with the context of that place. And the new pidkhid to animation and roam to rob the simplest zavdannya richly cliques.

Briefly, the principle of technology is as follows: on a flat glass panel, a telephone, which is called a display, scatters trivi- merny light, which collapses in space at once from the outbuildings.

Parallax and perspective

The principle of parallax-effect of foundations on how the brain defines the world of the object, which is in the field of vision of a person. The closer the object, the more wines are given. First of all, if they gave us an object, then there are fewer wines for the expansion.

The basic description was given to the principle of spryynyattya brain perspective, and the parallax є change of the visible camp of the object, but the distant ashes are fallow in the camp of the posterigach. For example, if you are in the middle of a car or a train, which is fast to rush, objects that are closer to you, collapse faster, at that hour, as if objects are farther away - more. Wanting to be honest, they have the same swedishness.

Along with other optical tricks, perspective and parallax play an important role in sprinyatti light, giving the ability to reason and arrange visual signals that register eyes.

Type of missiles to telephones

In iOS, the parallax effect is created by software, the technology itself, as it was first designed for space exploration.

In the middle of any mobile Apple device, there is an attachment under the name MEMS-gyroscope. Vіn carried in the middle of a crying mechanism (less than a human hair), the building vibrated at the main frequency when applying to a new electric signal. If you wrap your smartphone (or tablet) in three directions, the mechanism for using the middle of the gyroscope will repair the opir change of orientation according to Newton's First Law.

Working together with other sensors, called accelerometers, the gyroscope allows the attachment to perceive and determine the change of its position in space with great accuracy.

Starting from the assessment of the post position, based on the fact that more people raise the phone to the level of their eyes, to win it over, iOS designates the top of the phone’s display as the field of our vision, at that moment, if the stench moves like one alone.

Mathematics, which implements the glybin effect, can be done with idle time. All that is necessary for the software security is to organize the display in different areas, and then move these areas one by one. Move, basing on the original position of the eyes of the koristuvach. All the same, as a result, I create the effect of glibini.

If you watched the recording of the WWDC 2013 conference, you could remember that the icons in iOS 7 look like this, nibbut the stench is above the background trellises. I look even more realistic. Those same hundred and tabs in Safari.

Irrespective of the fact that all the features of iOS 7 are still popular with the public, it’s entirely possible that Apple will introduce a parallax effect in all warehouses of the new OS to the list of sub-trimming outbuildings).

How parallax works in iOS 7:

The idea of ​​using parallax in mobile app design is not new. Like a lot of others, it came to us from the world of web design, but it has become more and more wide-spread right away. Parallax gives the design an intimidating effect of depth and general. At the moment, due to the lack of hands, due to the specifics of the development of web add-ons, the fashion for parallax in the design of sites has subsided. However, mobile programs - tse zovsіm іnsha rozmov. Parallax in mobile design is alive and yet you don’t get anywhere to go, and get donations for the lock new iOS 7 design !

In this article, we will tell you about our DVParallaxView component, and we will demonstrate it on an example, I will add it, how to add such a parallax effect as an addition, like in the home screen in iOS 7. Navit more briefly.

How vlashtovanny parallax?

Let's take a short time to the harsh world of physics, in order to better understand and structure for ourselves the mechanism of the parallax effect. Tse help us to verify yoga on the screen of the phone.

Father, how does parallax work? The essence of yoga is simple. Parallax is a change in the position of one and the same object, which is guarded from two different points in space. Posposerіgat tsey effect in the real world can be mitigated. Everything you need - it’s more important for the role of the background (for example, the wall of the booth) and the object that guards against this aphid, which is closer to you, the lower background (for example, the light wall or the tree). If you take a break from the wall, guarding against it for the lichtarny stomp, then you should be aware that the likhtarny stovp is misplaced by the wall. Such an effect is called parallax - the sound of a stovpa, what is happening, it is clear when you move the point of caution, so you. With whomever will be closer to you, it will be better for you to get the security of your shift. First of all, if you see a stovp on a significant stand and try to walk through the wall again - stovp is practically not disturbed by the sound of the wall. Our eyes are attached to assess the objects for rich signs, and from them - the security of the object's location. How do you create a scene, in which objects in your country change with different swedishness - your eyes can tell your brain what objects are in different views of you. In this case, the preference for parallax effect in the design is similar - zіmіtuvavshi yogo, you will add a flat scene to the depth.

Also, for a practical sense for us, the effect of parallax is in the fact that objects in the distance from you at different times are different from different swedishness. Moreover, tsya swidkіst lie in your vіdstanі to ob'ektіv. If you are close - the speed of the object is great, if you are far away - on the other hand.

Let's see the main warehouse effect. Firstly, for a clearly pronounced parallax, mother fon is ideally unruly, otherwise there will be little shackled in a parallel with the object’s solution. In another way, parallax can be guarded only for the obviousness of objects, which reminds of the expanse between the background and the point of caution. And the most important thing in these objects is the difference of their distance from you. In other words, the ob'єkti are guilty of becoming their own ієrarchy, shuffling at different sights from the point of view to the background. I, nareshti, thirdly, the parallax of impossibility without the movement of objects at the same time as a point of caution with a different swedishness.

For the obviousness of all three main moments - the background, the objects and the perceptible rush - mi posterigatimemo parallax.

Parallax scrolling

Now, if we know, as parallax reigns, we need to sign up, as we ourselves inculcate yoga in the code.

The most obvious approach to implementing parallax is parallax scrolling. Did you play with an old platformer game? If so, then you can guess for everything that while the character was big from the left end of the river to the right, the objects in the background were in the opposite direction with a different swidkistyu fallow in the distance of the foreground. Axis of posting on Wikipedia, so you guessed exactly what to go about.

Parallax scrolling in games is so powerful that the scene, as you see it on the screen, is made up of a lot of balls, de-stashing objects. Fallen in front of the ball in front of the screen (the ball “fox” is closer to you, the lower ball is “gloomy”, as it is closer to you, the lower ball is “sun”) the balls are shifting from that other swidkist. Tse hope those who see a single clay on the screen, zmushyuyuchi a flat picture look about'mnishe. It is impossible not to know - such a pidkhіd to do well to spivvіdnositsya z tim, scho we knew about parallax. Really, you can break the space between you and the background on the balls, what to revenge the objects, what to know in this space.

It is logical to assume that the implementation of the parallax effect is due to being encapsulated in some component-container, to compensate for other components and may be a hierarchy of species, the position of which will be different from the position in the hierarchy. Let's ask ourselves, but what element is missing in UIKit, which one can take revenge on oneself? Zvіsno є! Whether it is a UIView to avenge the hierarchy of other UIViews placed by the addSubview: method.

Here we come to the main idea underlying our DVParallaxView component. The idea is that the component is a UIView patch that encapsulates the parallax effect in itself. The effect itself is implemented by passing a new contentOffset power value, which can be of the CGPoint type. In this way, DVParallaxView in its own way is similar to UIScrollView. When changing the contentOffset value, we change the skin view descaler, which is in the DVParallaxView hierarchy. The value of the usunennia will be at the back fallow in the distance of the element at the “top” of the hierarchy. The fragments of the element in the array of subviews are taken from the bottom in the hierarchy (then from the far view of the screen), then the shift is changed from the straight line of fallow to the index of the cultivated element during direct passage through the array. In such a way, we interpret the obviousness “to stand” between the elements, like in a real world. To control the size of the input, we will enter into the external power interface, which is a multiplier, by which the index of the element in the array will be multiplied. By doing yoga, you can always adjust the amount of parallax behind your tower.

Well, the proponated model looks lifelike, all the main points are thought out. Here we can put a note in the knowledge about the conceptual parallax device in DVParallaxView and start talking about its practical implementation.

Create DVParallaxView

In this next chapter, we report on the creation of the DVParallaxView component.

Before that, how to proceed directly to the implementation, let's take a look at the DVParallaxView class with more power.

In the first place, parallax looks the best and most often fights on aphids, which is the edge of the picture (remember, we were appointed, that one of the clothes of the warehouse parallax is the background?). So in our class it is necessary to transfer the ability to install a background image. The very root of the view hierarchy will always have a private element to the UIImageView class, which we call backgroundImageView. This element will play the role of the background in the DVParallaxView. Yogo roztashuvannya in the root of the hierarchy will guarantee us the least visible use, as if to belong to the background, the greatest object of the scene. To pass a background image to the public interface of a component, there will be a special authority - backgroundImage to the UIImage class.

In another way, the parallax effect in iOS 7 is not only due to the shift in the background. To be more surprised, you can note one detail: the icons move to the side, opposite to the background. It has been sharpened to strengthen the parallax effect and the contrast between the background, which is misplaced, and the icons of the add-ons, which at first glance look unruly. We set the shards for the meta to catch up and overtake parallax in iOS 7, we just goiter to add such a possibility to our component. For whom, we create a frontView in the public interface, in order to convey the view that we want to move to the opposite parallax side.

Otzhe, all the preparations are broken - the theory has been developed, the addition of a component of thought. You can proceed before closing the DVParallaxView. Are you ready?

Create a single-view project in XCode, give it a name and other required attributes. In the middle of the project, create the DVParallaxView class, which is the default UIView class. Create a DVParallaxView header file and save it in this order.

#import @interface DVParallaxView: UIView @property (nonatomic, strong) UIImage *backgroundImage; @property (nonatomic, strong) UIView *frontView; @property (nonatomic) float parallaxDistanceFactor; @property (nonatomic) float parallaxFrontFactor; @property (nonatomic) CGPoint contentOffset; @end

All the powers that be in the class, as you are here, we have already discussed more, that their recruitment is not to blame for you. Two powers, which were not discussed earlier in the explicit view - parallaxDistanceFactor and parallaxFrontFactor - these are multipliers, which serve to control the magnitude of the shift in the hierarchy of elements and the frontal view.

Create a private interface for the implementation file of the class. It needs to have the authority of the backgroundImageView, but the class doesn't have much to give it public access.

@interface DVParallaxView() @property (nonatomic, strong) UIImageView *backgroundImageView; @end

Let the class object be instantiated by calling the initWithFrame: method. In yoga, it is necessary to vikonate the entire cob configuration.

- (id)initWithFrame:(CGRect)frame ( self = ; if (self) ( self.parallaxDistanceFactor = 2.f; self.parallaxFrontFactor = 20.f; self.backgroundColor = ; ; UIPanGestureRecognizer *panRecognizer = :@selector(panHandler :)]; ; ) return self; )

We have given such meanings of multipliers, looking out of their own special likenesses. You can choose other values, so that the parallax will be too strong for you, or, on the other hand, too weak. Please note that the back of the body is on the cob to be found in the hierarchy of views;

If you have already asked “How can I initialize the visualization of the component?”, then you can already ask in the code of the initializer - UIPanGestureRecognizer. So, we remember that iOS 7 parallax called out to a smart phone. All the time.

The UIPanGestureRecognizer has a selector passed to the panHandler: method. Let's write this method right away, so that you don't forget to spend it all the time.

#pragma mark - Gesture handler - (void)panHandler:(UIPanGestureRecognizer *)pan ( CGPoint translation = ; ; ; )

Nothing extraordinary. The torsional displacement is readable and the same displacement value is set to our DVParallaxView. Do not forget to reset the otrimane usunennya in the world.

Now find more. While changing the contentOffset, nothing appears, let's fix it. Create a setter method setContentOffset as shown below.

-(void)setContentOffset:(CGPoint)contentOffset ( BOOL backgroundReachedEdgeX = NO; BOOL backgroundReachedEdgeY = NO; double contentDivider; //1 if (self.backgroundImageView) ( contentDivider = self.subviews.count*Gelf. (self.backgroundImageView.center .x + (contentOffset.x - _contentOffset.x)/contentDivider, self.backgroundImageView.center.y - (contentOffset.y - _contentOffset.y)/contentDivider);if ((newCenter.x - self .backgroundImageView.frame.size .width/2.f) > 0.f || (newCenter.x + self.backgroundImageView.frame.size.width/2.f)< self.bounds.size.width) { newCenter.x = self.backgroundImageView.center.x; backgroundReachedEdgeX = YES; } if ((newCenter.y - self.backgroundImageView.frame.size.height/2.f) >0.f || (newCenter.y + self.backgroundImageView.frame.size.height/2.f)< self.bounds.size.height) { newCenter.y = self.backgroundImageView.center.y; backgroundReachedEdgeY = YES; } self.backgroundImageView.center = newCenter; } // //2 for (int i = 1; i

Otzhe, let's take a look at the method of reporting. Change backgroundReachedEdgeX and backgroundReachedEdgeY to serve as a signal about those who have reached the edge of the picture. As a background image, you can't override what we see between backgroundImage images. Aja, we don’t want to, so that the coristuvachi look at the shaving of the image, they look unnatural. Therefore, we vvazhali for the need to surround the area of ​​​​parallax with the dimensions of the image of the background, as it were. In this order, block //1 to avenge your own re-examination for the interim image.

Block //2 - the whole passage for all the elements of the ієrarchy, seeing from the rozrakhunkom the values ​​of the used centers of the fallow land in the ієrarchy. So, if we know the X or Y axes at the edge of the background image, then there will be no displacement of these axes.

The main logic of the displacement has been created, a lot has been left out - set a method for accessing the main authorities, as well as revantaging the addSubview method.

#pragma mark - Getters -(UIImageView *)backgroundImageView ( if (!_backgroundImageView) ( _backgroundImageView = [ init]; _backgroundImageView.contentMode = UIViewContentModeCenter; _backgroundImageView.center = CGPointMake(CGRectGetMidX(self.sel) ; ) return _backgroundImageView; ) #pragma mark - Setters -(void)setParallaxDistanceFactor:(float)parallaxDistanceFactor ( _parallaxDistanceFactor = MAX(0.f, parallaxDistanceFactor); ) -(void)setParallaxFront .f, parallaxFrontFactor); ) -(void)setBackgroundImage:(UIImage *)backgroundImage ( _backgroundImage = backgroundImage; ; CGPoint origin = CGPointMake(CGRectGetMidX(self.bounds) - backgroundImage.size.width/2.f, CGRectG. bounds) - backgroundImage.size.height /2.f), self.backgroundImageView.frame = (CGRect)(.origin = origin, .size = backgroundImage.size); _frontView = frontView; ; ) #pragma mark - Overriding -(void)addSubview:(UIView *)view ( if (self.frontView) ; else ; )

Let's go in order. With a getter for backgroundImageView, everything was clear - it's more lazy instantiation, we create an object as needed. When the ParallaxDistanceFactor value is set, the ParallaxFrontFactor will automatically change to a negative value. The setter for backgroundImage sets the background image in the backgroundImageView and simultaneously centers it on the screen. The frontView setter instantly adds the frontView to the view hierarchy, so there's no point in adding it manually. Nareshti, the addSubview method has been changed: it works in the default mode, even though the frontView is not assigned in DVParallaxView, but if the assignment is wrong, then either view will be in a position lower than the new one in the hierarchy. Even if you are worried about the frontView, keep it in front.

For the time being, let's move on to the main viewController of our test project. The hour has come to connect our new component and rewrite yoga at the right. If we want to be similar to the new home screen in iOS 7, then we can try it out for a test project. For which we need a picture of the background (from space images) and icons of add-ons. More than that, our component shards support other objects between the background and the foreground, mi dodamo them tezh. As the background is the cosmos, then the cosmic theme and the trochs of the lively empty cosmic expanse of the planet Earth and its companion - the Moon. You can find the necessary images on the Internet or take them from our test project on github.

In iOS 7, the program icons are in the foreground, so in DVParallaxView we are responsible for placing them in the frontView. For whom we create UIView, to what extent we can save all icons. To avoid manually creating and placing all these components, create a container and icons at the storyboard, then connect them to the controller.

The axis looks like the front view of our test attachment. Bind the UIView container as an IBOutlet to the controller and name it frontView. Let's get down to creating the DVParallaxView instance.

Set parallaxView power to your controller's private interface. For whom domineering create a getter.

-(DVParallaxView *)parallaxView ( if (!_parallaxView) ( _parallaxView = [ initWithFrame:self.view.bounds]; [_parallaxView setBackgroundImage:]; UIImageView *earth = [ initWithImage:]; earth.frame = (CGRect) (.origin ) = CGPointMake(CGRectGetMidX(self.view.bounds) - earth.image.size.width/2.f, CGRectGetMidY(self.view.bounds) - earth.image.size.height/2.f), .size = earth .frame.size);[_parallaxView addSubview:earth];UIImageView *moon=[initWithImage:];moon.frame=(CGRect) self.view.bounds) + 30.f), .size = moon.frame.size );[_parallaxView addSubview:moon];[_parallaxView setFrontView:self.frontView];

In the code, it is clear that after the creation of an instance of the DVParallaxView class, the background “galaxy2” is set for it, then images of the Earth and the Moon are added to the view hierarchy. Then, as the foreground, the authority of the frontView is set. Now all that's left is to add our component to the controller view hierarchy. Add the whole row to the viewDidLoad method:

;

Parallax is ready, you can start the project. As a result of our creations, the component at the same stage of its development gives a completely reliable parallax effect.

Lost just one detail. For the time being, the usunennya elements are beaten by dots. It's time to fix it. It's time to connect to the DVParallaxView gyroscope.

Connectable Core Motion

If you have read our article, then you already have all the necessary skills for using a gyroscope in this project, and you also know that for connecting a gyroscope it is necessary to add the Core Motion framework to the project. Ale, how do we vikoristovuvatimemo data from the sensor? RotationRate was chosen for the project to indicate how bad it is on the phone. So the contentOffset is changed due to the presence of a non-zero apex shift.

Connect the framework to the implementation file of the DVParallaxView class.

#import

Let's create the power of motionManager and displayLink in a private interface class.

@property (nonatomic, strong) CMMotionManager *motionManager;

@property (nonatomic, strong) CADisplayLink *displayLink;

CMMotionManager is the main CoreMotion class that is used to access data from sensors. CADisplayLink - a timer, which works with the frequency of screen updates, which is a wake-up method for updating data from a gyroscope.

Now dodamo methods and access to new authorities.

-(CADisplayLink *)displayLink ( if (!_displayLink) ( _displayLink = ; ) return _displayLink; ) -(CMMotionManager *)motionManager ( if (!_motionManager) ( _motionManager = [ init]; _motionManager.deviceMotionUpdateInterval = 0.03f; ) ;)

Obviously, for the retailer, which is the DVParallaxView component, it is necessary to set the gyroscope to vicorist. Perhaps, there will be other ways to change the contentOffset value. The component is to blame for this to give the possibility of choice, which is necessary to be parallaxed through the gyroscope. For this choice, we introduce gyroscopeControl into the public interface, which is the BOOL type. If it is set to YES, the component starts to read the indication from the gyroscope and offset the elements of the hierarchy when the attachment is bad. As it is installed in NO, the component reacts to changes in the apex of the structure. With any power, motionManager and displayLink are responsible for their responsibility, so as not to take away the resources of the processor for nothing.

As we have managed to create a gyroscopeControl at the huge interface.

@property (nonatomic, strong) BOOL gyroscopeControl;

Let's create something for the new sister.

-(void)setGyroscopeControl:(BOOL)gyroscopeControl ( if (_gyroscopeControl == gyroscopeControl) return; _gyroscopeControl = gyroscopeControl; if (gyroscopeControl) ( ; forMode:NSDefaultRunLoopMode]; ) else ( ; ) ;

Note that when you set the power to YES, the motionManager starts to take the reading from the deviceMotion and not from the gyroscope. The reasons for this choice are reportedly described in the article. When set to NO, the data is removed, the displayLink is removed from the existing streams by calling the invalidate method, and the motionManager itself is set to nil.

Now we have no more to write a method for converting data from a gyroscope into data for contentOffset, as well as to implement the displayLinkHandler method, which is invoked by the displayLink timer.

#pragma mark - Gyroscope to offset - (CGPoint)contentOffsetWithRotationRate:(CMRotationRate)rotationRate ( double xOffset = (fabs(rotationRate.y) > DV_ROTATION_THRESHOLD)?rotationRate.y*DV_ROTATION_MULTIPLIER x) > DV_ROTATION_THRESHOLD)?rotationRate.x*DV_ROTATION_MULTIPLIER:0 .f; )

Don't forget to describe two define-constants to the implementation file, which we used in the transformation method.

#define DV_ROTATION_THRESHOLD 0.1f

#define DV_ROTATION_MULTIPLIER 2.5f

For the DVParallaxView object creation time controller class, set the power of gyroscopeControl to YES.

Otzhe, the gyroscope of connections, the data of the new guilt are now correctly converted to the shift. Now you can compile the project and run yoga on the extension. You look good, don't you? Respectfully, the gyroscope is less practicable on a real extension.

Visnovok

As you read this paragraph, it means that you have successfully created an okremy component with the parallax effect, like in iOS 7. See more - the effect of the DVParallaxView component is higher, the shards are not only the background and the foreground, but also the element's archiving. Like a bachite, yoga attachments are not foldable.

DVParallaxView was created by us for free submissions to our repository. Shout, paint, we will be happy with your propositions!

© 2022 androidas.ru - All about Android