disable pointer when enlarged image is hidden
Change-Id: I6c637a4d8d8e0e3ffdeeb29ea98ca184d198355e
This commit is contained in:
Binary file not shown.
@@ -65,9 +65,9 @@
|
|||||||
|
|
||||||
- (void)startMotionDetect
|
- (void)startMotionDetect
|
||||||
{
|
{
|
||||||
// __block float stepMoveFactorX = 5;
|
// __block float stepMoveFactorX = 5;
|
||||||
// __block float stepMoveFactorY = 5;
|
// __block float stepMoveFactorY = 5;
|
||||||
// __block double refX, refY;
|
// __block double refX, refY;
|
||||||
|
|
||||||
[self.motionManager
|
[self.motionManager
|
||||||
startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init]
|
startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init]
|
||||||
@@ -76,38 +76,38 @@
|
|||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(),
|
dispatch_async(dispatch_get_main_queue(),
|
||||||
^{
|
^{
|
||||||
CGRect rect = self.movingPointer.frame;
|
CGRect rect = self.movingPointer.frame;
|
||||||
NSLog(@"x:%f y:%f z:%f", data.acceleration.x, data.acceleration.y, data.acceleration.z);
|
NSLog(@"x:%f y:%f z:%f", data.acceleration.x, data.acceleration.y, data.acceleration.z);
|
||||||
// Used to calibrate pointer based on initial position
|
// Used to calibrate pointer based on initial position
|
||||||
// if (self.pointerCalibrationOn){
|
// if (self.pointerCalibrationOn){
|
||||||
// refX = data.acceleration.x;
|
// refX = data.acceleration.x;
|
||||||
// refY = data.acceleration.y;
|
// refY = data.acceleration.y;
|
||||||
// self.pointerCalibrationOn = NO;
|
// self.pointerCalibrationOn = NO;
|
||||||
// }
|
// }
|
||||||
// float movetoX = rect.origin.x + ((data.acceleration.x - refX) * stepMoveFactorX);
|
// float movetoX = rect.origin.x + ((data.acceleration.x - refX) * stepMoveFactorX);
|
||||||
|
|
||||||
float movetoX = self.touchPointerImage.frame.origin.x + self.touchPointerImage.frame.size.width * ABS(data.acceleration.x - self.refLeftUpperGravity.x) / ABS(self.refRightUpperGravity.x - self.refLeftUpperGravity.x);
|
float movetoX = self.touchPointerImage.frame.origin.x + self.touchPointerImage.frame.size.width * ABS(data.acceleration.x - self.refLeftUpperGravity.x) / ABS(self.refRightUpperGravity.x - self.refLeftUpperGravity.x);
|
||||||
float maxX = self.touchPointerImage.frame.origin.x + self.touchPointerImage.frame.size.width - rect.size.width;
|
float maxX = self.touchPointerImage.frame.origin.x + self.touchPointerImage.frame.size.width - rect.size.width;
|
||||||
|
|
||||||
// float movetoY = (rect.origin.y) + ((data.acceleration.y - refY) * stepMoveFactorY);
|
// float movetoY = (rect.origin.y) + ((data.acceleration.y - refY) * stepMoveFactorY);
|
||||||
float movetoY = self.touchPointerImage.frame.origin.y + self.touchPointerImage.frame.size.height * ABS(data.acceleration.y - self.refRightUpperGravity.y) / ABS(self.refRightLowerGravity.y - self.refRightUpperGravity.y);
|
float movetoY = self.touchPointerImage.frame.origin.y + self.touchPointerImage.frame.size.height * ABS(data.acceleration.y - self.refRightUpperGravity.y) / ABS(self.refRightLowerGravity.y - self.refRightUpperGravity.y);
|
||||||
float maxY = self.touchPointerImage.frame.origin.y + self.touchPointerImage.frame.size.height;
|
float maxY = self.touchPointerImage.frame.origin.y + self.touchPointerImage.frame.size.height;
|
||||||
|
|
||||||
if ( movetoX > self.touchPointerImage.frame.origin.x && movetoX < maxX ) {
|
if ( movetoX > self.touchPointerImage.frame.origin.x && movetoX < maxX ) {
|
||||||
rect.origin.x = movetoX;
|
rect.origin.x = movetoX;
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( movetoY > self.touchPointerImage.frame.origin.y && movetoY < maxY ) {
|
if ( movetoY > self.touchPointerImage.frame.origin.y && movetoY < maxY ) {
|
||||||
rect.origin.y = movetoY;
|
rect.origin.y = movetoY;
|
||||||
};
|
};
|
||||||
|
|
||||||
[UIView animateWithDuration:0 delay:0
|
[UIView animateWithDuration:0 delay:0
|
||||||
options:UIViewAnimationOptionCurveEaseIn
|
options:UIViewAnimationOptionCurveEaseIn
|
||||||
animations:^{
|
animations:^{
|
||||||
self.movingPointer.frame = rect;
|
self.movingPointer.frame = rect;
|
||||||
}
|
}
|
||||||
completion:nil
|
completion:nil
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@@ -186,29 +186,33 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
UITouch *touch = [[event allTouches] anyObject];
|
if (!self.touchPointerImage.isHidden){
|
||||||
CGPoint loc = [touch locationInView:self.touchPointerImage];
|
UITouch *touch = [[event allTouches] anyObject];
|
||||||
if (loc.x >= 0 && loc.x <= self.touchPointerImage.frame.size.width
|
CGPoint loc = [touch locationInView:self.touchPointerImage];
|
||||||
&& loc.y >= 0 && loc.y <= self.touchPointerImage.frame.size.height){
|
if (loc.x >= 0 && loc.x <= self.touchPointerImage.frame.size.width
|
||||||
CGPoint p;
|
&& loc.y >= 0 && loc.y <= self.touchPointerImage.frame.size.height){
|
||||||
p.x = loc.x + self.touchPointerImage.frame.origin.x;
|
CGPoint p;
|
||||||
p.y = loc.y + self.touchPointerImage.frame.origin.y;
|
p.x = loc.x + self.touchPointerImage.frame.origin.x;
|
||||||
self.movingPointer.center = p;
|
p.y = loc.y + self.touchPointerImage.frame.origin.y;
|
||||||
[self.movingPointer setHidden:NO];
|
self.movingPointer.center = p;
|
||||||
|
[self.movingPointer setHidden:NO];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
UITouch *touch = [[event allTouches] anyObject];
|
if (!self.touchPointerImage.isHidden){
|
||||||
CGPoint loc = [touch locationInView:self.touchPointerImage];
|
UITouch *touch = [[event allTouches] anyObject];
|
||||||
if (loc.x >= 0 && loc.x <= self.touchPointerImage.frame.size.width
|
CGPoint loc = [touch locationInView:self.touchPointerImage];
|
||||||
&& loc.y >= self.movingPointer.frame.size.height && loc.y <= self.touchPointerImage.frame.size.height - self.movingPointer.frame.size.height)
|
if (loc.x >= 0 && loc.x <= self.touchPointerImage.frame.size.width
|
||||||
{
|
&& loc.y >= self.movingPointer.frame.size.height && loc.y <= self.touchPointerImage.frame.size.height - self.movingPointer.frame.size.height)
|
||||||
CGPoint p;
|
{
|
||||||
p.x = loc.x + self.touchPointerImage.frame.origin.x;
|
CGPoint p;
|
||||||
p.y = loc.y + self.touchPointerImage.frame.origin.y;
|
p.x = loc.x + self.touchPointerImage.frame.origin.x;
|
||||||
self.movingPointer.center = p;
|
p.y = loc.y + self.touchPointerImage.frame.origin.y;
|
||||||
|
self.movingPointer.center = p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user