Home/Patches, Uncategorized/Coping with clicking controls on iOS7 devices

Coping with clicking controls on iOS7 devices

Views:
9

UPDATE: If you’ve applied Update 1 for XE5, please revert any changes made based on this article, or ignore it if you have not made any changes. The issue has been resolved in Update 1 for the DEVICE;  Update 1 causes an issue with  clicking controls in the simulator. Please refer to this article if you have installed Update 1.

If you’ve read this article:

http://delphi.radsoft.com.au/2013/10/coping-with-done-bar-on-ios7-devices/

You’ll know that on iOS7 devices (note: not on the simulator), there appears to be an issue related to how iOS7 considers the screen area, which means that coordinates are off by the height of the status bar at the top of the device. This also affects the coordinates given when a control is “clicked”, and can result in the wrong control being “clicked”, or a control not receiving a click at all.

The solution is to modify the TFMXViewBase.GetTouchCoord method in the unit FMX.Platform.iOS. Make a copy of the unit and put it somewhere in your library path, or just in the project directory, and make the following changes:

function TFMXViewBase.GetTouchCoord(const touches: NSSet; const Window: UIView; var x, y: single): Boolean;
var
  touch : UITouch;
  p     : CGPoint;
  // Add the following lines
  App: UIApplication;
  Device: UIDevice;
  Offset: Single;
begin
  Result := False;
  if Assigned(touches) and (touches.count = 1) then
  begin
    // Add the following lines:
    Offset := 0;
    {$IFDEF CPUARM}
    App := TUIApplication.wrap(TUIApplication.OCClass.SharedApplication);
    Device := TUIDevice.Wrap(TUIDevice.OCClass.currentDevice);
    if Pos('7', Device.systemVersion.UTF8String) = 1 then
      Offset := App.statusBarFrame.size.height;
    {$ENDIF}
    touch := TUITouch.Wrap(touches.anyObject);
    p := touch.locationInView(Window);
    x := p.x;
    // Comment out this line
    // y := p.y;
    // Add this line
    y := p.y - Offset;
    PlatformCocoa.FMouseCoord.X := X;
    PlatformCocoa.FMouseCoord.Y := Y;
    PlatformCocoa.FMouseCoord := Form.ClientToScreen(PlatformCocoa.FMouseCoord);
    Result := True;
  end;
end;

Now you should find that the “clicks” are in the right place.

By | 2014-10-19T16:54:48+00:00 October 23, 2013 6:54 am|Patches, Uncategorized|0 Comments

About the Author:

Leave a Reply

Show Buttons
Hide Buttons