Мой пользовательский класс ImgButton наследуется от Grid. В других случаях вам просто нужно заменить ViewRenderer другим средством визуализации согласно этой [таблице]. [1]
Поскольку я хочу, чтобы долгое нажатие было включено только в определенных случаях, ImgButton имеет свойство EnableLongPress.
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using UIKit;
[assembly: ExportRenderer (typeof(ImgButton), typeof(ImgButtonRenderer))]
namespace MyApp.iOS.Renderers
{
public class ImgButtonRenderer : ViewRenderer<ImgButton,ImgButtonRenderer>
{
private UILongPressGestureRecognizer longPressGestureRecognizer;
protected override void OnElementChanged ( ElementChangedEventArgs<ImgButton> e )
{
base.OnElementChanged ( e );
if ( e.NewElement != null )
{
if ( ! e.NewElement.EnableLongPress )
return;
Action longPressAction = new Action ( () =>
{
if ( longPressGestureRecognizer.State != UIGestureRecognizerState.Began )
return;
Console.WriteLine ( "Long press for " + e.NewElement.Text );
// Handle the long press in the PCL
e.NewElement.OnLongPress ( e.NewElement );
});
longPressGestureRecognizer = new UILongPressGestureRecognizer ( longPressAction );
longPressGestureRecognizer.MinimumPressDuration = 0.5D;
AddGestureRecognizer ( longPressGestureRecognizer );
}
if ( e.NewElement == null )
{
if ( longPressGestureRecognizer != null )
{
RemoveGestureRecognizer ( longPressGestureRecognizer );
}
}
if ( e.OldElement == null )
{
if ( longPressGestureRecognizer != null )
AddGestureRecognizer ( longPressGestureRecognizer );
}
}
}
И в классе ImgButton:
public void OnLongPress ( ImgButton button )
// Here when a long press happens on an ImgButton
{
// Inform current page
MessagingCenter.Send<ImgButton, ImgButton> ( this, "LongPressMessageType", button );
}
{вот код, чтобы сделать это. Используйте объект TProcess!}
uses Process;
...
procedure DoProcess;
Var
Proc : TProcess;
Begin
Proc := TProcess.Create(nil);
try
Proc.CommandLine := '/Applications/MyApp.app';
PRoc.Options := Proc.Options + [poWaitOnExit];
Proc.CommandLine := Proc.CommandLine + ' -someparam';
PRoc.Execute;
finally
Proc.free;
end;
End;
Я не знаю, перенесли ли библиотекам Lazarus действительно уже эту функциональность, но если не Вы могли бы записать условно скомпилированную версию ShellExecute () использование информации в Руководстве по программированию Launch Services.
Я успешно использовал Shell('open ' + Filename)
в OS X 10.4 и 10.3, который, кажется, работает скорее приятно на большинство типов файлов.
Я споткнулся через open
при приглашении оболочки и теперь пропускают его в cygwin/linux и т.д.