using System;
using Foundation;
using Shared.IO;
using UIKit;
namespace Shared
{
///
/// ImageView
///
public class ImageView : View
{
MyImageView myImageView
{
get
{
return uiView as MyImageView;
}
set
{
uiView = value;
}
}
///
/// Initializes a new instance of the class.
///
public ImageView()
{
myImageView = new MyImageView(this) { };
}
internal string imagePath, tempImagePath;
///
/// 非选中状态的背景图路径
///
/// The un selected image path.
public string ImagePath
{
get
{
return imagePath;
}
set
{
tempImagePath = value;
if (!IsCanRefresh)
{
return;
}
if (imageBytes != null)
{
myImageView.SetBackgroundImage(UIImage.LoadFromData(NSData.FromArray(imageBytes)), UIControlState.Normal);
return;
}
if (ImagePath == value)
{
return;
}
imagePath = value;
myImageView.SetBackgroundImage(UIImage.FromFile(FileUtils.GetImageFilePath(imagePath)), UIControlState.Normal);
}
}
byte[] imageBytes;
public byte[] ImageBytes
{
get
{
return imageBytes;
}
set
{
imageBytes = value;
ImagePath = tempImagePath;
}
}
public override void Refresh()
{
base.Refresh();
ImagePath = tempImagePath;
}
}
class MyImageView : UIKit.UIButton
{
[Weak] View view;
public MyImageView(View view)
{
this.view = view;
}
///
/// 点击开始
///
/// Touches.
/// Evt.
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
view?.TouchEvent(EventActions.Down, (touches.AnyObject as UITouch).LocationInView(this));
}
///
/// 移动
///
/// Touches.
/// Evt.
public override void TouchesMoved(NSSet touches, UIEvent evt)
{
view?.TouchEvent(EventActions.Move, (touches.AnyObject as UITouch).LocationInView(this));
}
///
/// 点击弹起
///
/// Touches.
/// Evt.
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
view?.TouchEvent(EventActions.Up, (touches.AnyObject as UITouch).LocationInView(this));
}
public override void TouchesCancelled(NSSet touches, UIEvent evt)
{
view?.TouchEvent(EventActions.Cancel, (touches.AnyObject as UITouch).LocationInView(this));
}
}
}