Hi,
I placed an TTMSFMXNativeUICollectionViewTemplateImageView inside a TTMSFMXNativeUICollectionView, with a small size.
When selecting the item I want the Image to get bigger in size.
When selecting another image I want the previously selected image to get small again.
AllowsMultipleSelection is set to false.
procedure TFCollectionView.FormCreate(Sender: TObject);
begin
// Set two Items per Row
// Set Item.Width to half of CollectionView.Width
// Set Item.Height to half the Item.Width
TMSFMXNativeUICollectionView1.Options.ItemWidth := TMSFMXNativeUICollectionView1.Width/2 - 6;
TMSFMXNativeUICollectionView1.Options.ItemHeight := TMSFMXNativeUICollectionView1.Width/4;
// Set Image to half the Itemheight, square
TMSFMXNativeUICollectionViewTemplateImageView1.x := 0;
TMSFMXNativeUICollectionViewTemplateImageView1.y := 0;
TMSFMXNativeUICollectionViewTemplateImageView1.Height := TMSFMXNativeUICollectionView1.Options.ItemHeight/2;
TMSFMXNativeUICollectionViewTemplateImageView1.Width := TMSFMXNativeUICollectionView1.Options.ItemHeight/2;
TMSFMXNativeUICollectionViewTemplateLabel1.X := TMSFMXNativeUICollectionViewTemplateImageView1.Width + 6;
TMSFMXNativeUICollectionViewTemplateLabel1.y := 0;
end;
procedure TFCollectionView.TMSFMXNativeUICollectionView1DidDeselectItem(Sender: TObject; ASection, ARow: Integer);
var
aControl : TTMSFMXNativeUICollectionViewTemplateControl;
begin
// when Item is deselected set image size to half height of Item
aControl := TMSFMXNativeUICollectionView1.GetItemTemplateControl(ASection, ARow, 1);
if Assigned(aControl) and IsImageView(aControl) then begin
AsImageView(aControl).Height := TMSFMXNativeUICollectionView1.Options.ItemHeight / 2;
AsImageView(aControl).Width := TMSFMXNativeUICollectionView1.Options.ItemHeight / 2;
end;
end;
procedure TFCollectionView.TMSFMXNativeUICollectionView1DidselectItem(Sender: TObject; ASection, ARow: Integer);
var
aControl : TTMSFMXNativeUICollectionViewTemplateControl;
begin
// when Item is selected set image size to full height of Item
aControl := TMSFMXNativeUICollectionView1.GetItemTemplateControl(ASection, ARow, 1);
if Assigned(aControl) and IsImageView(aControl) then begin
AsImageView(aControl).height := TMSFMXNativeUICollectionView1.Options.ItemHeight;
AsImageView(aControl).width := TMSFMXNativeUICollectionView1.Options.ItemHeight;
end;
end;
when running the app various images are small, others are big ...
What am I doing wrong?
Thanks in advance,
Dietrich
Hi,
is it not possible to access the clone?
I also want to set a button to visible := false, if the item is not selected for a more simple design
Thanks in advance,
Dietrich
Accessing the clone is demonstrated in the sample.
Cool,
Thanks!
I still can't find my way.
This is how far I got:
procedure TForm20.TMSFMXNativeUICollectionView1DidDeselectItem(Sender: TObject; ASection, ARow: Integer);
var
c: UIcollectionviewCell;
i: NSIndexPath;
begin
i := TNSIndexPath.Wrap(TNSIndexPath.OCClass.indexPathForRow(ARow, ASection));
c := TMSFMXNativeUICollectionView1.CollectionView.cellForItemAtIndexPath(i);
if Assigned(c) then begin
// Need help for making Image smaller:
//... image.SetBounds(...)
end;
end;
procedure TForm20.TMSFMXNativeUICollectionView1DidselectItem(Sender: TObject; ASection, ARow: Integer);
var
c: UIcollectionviewCell;
i: NSIndexPath;
begin
i := TNSIndexPath.Wrap(TNSIndexPath.OCClass.indexPathForRow(ARow, ASection));
c := TMSFMXNativeUICollectionView1.CollectionView.cellForItemAtIndexPath(i);
if Assigned(c) then begin
// need help for making Image larger:
//... image.SetBounds(...)
end;
end;
Hi,
sure,
but I want to access the CityTrip.ItemImage not the DetailView.DetailImage from the CollectionView-Example ...
Please show how.
Thanks,
Dietrich
Perhaps you can try with the following code
Hi,
I extended the code with "contentview" to reach the UIImageView.
When selecting the cell, the imageView changes the size correctly.
But
when I scroll down the collection, several cells are resized although I
never selected them (They are resized periodically ...).
Why?
I
just want the user to select a cell which resizes the image contained
in that cell. All other images should stay in original size.
procedure TForm1.TMSFMXNativeUICollectionView1DidselectItem(Sender: TObject; ASection, ARow: Integer);
var
c : UIcollectionviewCell;
idx : NSIndexPath;
i : Integer;
v : UIView;
p : Pointer;
img : UIImageView;
f : NSRect;
begin
idx := TNSIndexPath.Wrap(TNSIndexPath.OCClass.indexPathForRow(ARow, ASection));
c := TMSFMXNativeUICollectionView1.CollectionView.cellForItemAtIndexPath(idx);
if Assigned(c) then begin
for i := 0 to c.contentview.subviews.count - 1 do begin
p := c.contentview.subviews.objectAtIndex(i);
v := TUIView.Wrap(p);
if v.isKindOfClass(objc_getClass('UIImageView')) then begin
f := TMSFMXNativeUICollectionViewTemplateImageView1.ImageView.frame;
f.size.width := TMSFMXNativeUICollectionViewTemplateImageView1.ImageView.frame.size.width + 100;
img := TUIImageView.Wrap(p);
img.setFrame(f);
end;
end;
end;
end;
Hi,
procedure TForm41.TMSFMXNativeUICollectionView1ApplyItemValue(Sender: TObject;
AControl: TTMSFMXNativeUICollectionViewTemplateControl; ASection,
ARow: Integer);
var
c : UIcollectionviewCell;
idx : NSIndexPath;
i : Integer;
v : UIView;
p : Pointer;
img : UIImageView;
f : NSRect;
begin
if (FSection = ASection) and (FRow = ARow) then
begin
idx := TNSIndexPath.Wrap(TNSIndexPath.OCClass.indexPathForRow(ARow, ASection));
c := TMSFMXNativeUICollectionView1.CollectionView.cellForItemAtIndexPath(idx);
if Assigned(c) then
begin
for i := 0 to c.contentview.subviews.count - 1 do
begin
p := c.contentview.subviews.objectAtIndex(i);
v := TUIView.Wrap(p);
if v.isKindOfClass(objc_getClass('UIImageView')) then
begin
f := TMSFMXNativeUICollectionViewTemplateImageView1.ImageView.frame;
f.size.width := TMSFMXNativeUICollectionViewTemplateImageView1.ImageView.frame.size.width + 100;
img := TUIImageView.Wrap(p);
img.setFrame(f);
end;
end;
end;
end;
procedure TForm41.TMSFMXNativeUICollectionView1DidselectItem(Sender: TObject;
ASection, ARow: Integer);
begin
FSection := ASection;
FRow := ARow;
TMSFMXNativeUICollectionView1.ReloadData;
end;
Hi,
thanks for fast answer.
I tried this approach but the problem is that c is never assigned:
Can you try the following instead
procedure TForm1.CityTripApplyItemValue(Sender: TObject;
AControl: TTMSFMXNativeUICollectionViewTemplateControl; ASection,
ARow: Integer);
begin
if IsImageView(AControl) and (ASection = FSection) and (ARow = FRow) then
AsImageView(AControl).Width := 100;
end;
OK!
I modified your idea and it works!
procedure TForm1.TMSFMXNativeUICollectionView1ApplyItemValue(Sender: TObject; AControl: TTMSFMXNativeUICollectionViewTemplateControl; ASection, ARow: Integer);
begin
if IsImageView(AControl) then begin
if (ASection = FSection) and (ARow = FRow) then
AControl.Width := 150
else
AControl.Width := 250;
AsImageView(AControl).ImageFile := TPath.combine(TPath.GetDocumentsPath, GetImageName(ASection, ARow));
end;
end;
procedure TForm1.TMSFMXNativeUICollectionView1DidDeSelectItem(Sender: TObject; ASection, ARow: Integer);
begin
FRow := -1;
FSection := -1;
TMSFMXNativeUICollectionView1.ReloadItem(ASection, ARow);
end;
procedure TForm1.TMSFMXNativeUICollectionView1DidSelectItem(Sender: TObject; ASection, ARow: Integer);
begin
FRow := ARow;
FSection := ASection;
TMSFMXNativeUICollectionView1.ReloadItem(ASection, ARow);
end;
Thanks a lot!
Dietrich
Thank you for your confirmation.