2017년 1월 31일 화요일

자마린 스튜디오(Xamarin Studio)에서 작성한 간단한 애니메이션 코드 입니다.

버튼이 회전하는 간단한 애니메이션 코드입니다. 재물로 버튼을 디자인하고 클릭하면 360도 회전하도록 되어 있습니다. 

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:DemoAnimation" x:Class="DemoAnimation.DemoAnimationPage">

    <Button x:Name="button"
            Text="Tap Me!"
            FontSize="Large"
            HorizontalOptions="Center"
            VerticalOptions="Center"
            Clicked="OnButtonClicked" />
    
</ContentPage>


using Xamarin.Forms;
using System; 

namespace DemoAnimation
{
    public partial class DemoAnimationPage : ContentPage
    {
        public DemoAnimationPage()
        {
            InitializeComponent();
        }

        void OnButtonClicked(object sender, EventArgs args)
        {
            button.RotateTo(360); 
        }
    }
}



자마린 스튜디오(Xamarin Studio)에서 변환(Translation) 사용하기

웹에서는 css를 사용해서 변환이나 애니메이션 효과를 줄 수 있습니다. 
iOS에도 다양한 코코아 기반의 변환과 애니메이션 효과를 줄 수 있습니다. 자마린에서는 재물에서 제공하는 선언된 태그를 사용해서 비슷하게 효과를 낼 수 있습니다. 
슬라이더를 변경하면 x축과 y축이 변경되는 것을 볼 수 있다.


<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:DemoTranslation" x:Class="DemoTranslation.DemoTranslationPage">

    <StackLayout Padding="20, 10">
        <Frame x:Name="frame" 
                HorizontalOptions="Center"
                VerticalOptions="CenterAndExpand"
                OutlineColor="Accent">

            <Label Text="TEXT"
                    FontSize="Large" />
        </Frame>

        <Slider x:Name="xSlider"
                Minimum="-200"
                Maximum="200"
                Value="{Binding Source={x:Reference frame}, 
                    Path=TranslationX}" />
         <Label Text="{Binding Source={x:Reference xSlider},
             Path=Value,
             StringFormat='TranslationX = {0:F0}'}"
             HorizontalTextAlignment="Center" />
        <Slider x:Name="ySlider"
            Minimum="-200"
             Maximum="200"
             Value="{Binding Source={x:Reference frame},
             Path=TranslationY }" />
         <Label Text="{Binding Source={x:Reference ySlider},
             Path=Value,
             StringFormat='TranslationY = {0:F0}'}" />
    </StackLayout>
</ContentPage>


자마린 스튜디오(Xamarin Studio)에서 비동기로 이미지 받아오기

이미지의 경우 속도가 느리기 때문에 대부분 비동기 형태로 웹서버에서 받아와야 합니다.
iOS의 경우 GCD를 제공합니다. 닷넷의 경우 await/async를 결합해서 보다 쉽게 사용할 수 있습니다.

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:DemoBacktoWeb" x:Class="DemoBacktoWeb.DemoBacktoWebPage">

     <ContentPage.Padding>
         <OnPlatform x:TypeArguments="Thickness"
             iOS="0, 20, 0, 0" />
        </ContentPage.Padding>
    
      <StackLayout>
         <Grid VerticalOptions="FillAndExpand">
             <Label x:Name="errorLabel"
                 HorizontalOptions="Center"
                 VerticalOptions="Center" />
             <ActivityIndicator IsRunning="{Binding Source={x:Reference image},
                 Path=IsLoading}" />
             <Image x:Name="image" />
         </Grid>
        
         <Button Text="Load Bitmap"
             HorizontalOptions="Center"
             Clicked="OnLoadButtonClicked" />
     </StackLayout>
</ContentPage>


using System.Net;

namespace DemoBacktoWeb
{
    public partial class DemoBacktoWebPage : ContentPage
    {
        public DemoBacktoWebPage()
        {
            InitializeComponent();
        }

        async void OnLoadButtonClicked(object sender, EventArgs args)
        {
            try
            {
                Stream stream =
                    await GetStreamAsync("https://developer.xamarin.com/demo/IMG_1996.JPG");
                image.Source = ImageSource.FromStream(() => stream);
            }
            catch (Exception exc)
            {
                errorLabel.Text = exc.Message;
            }
        }

        async Task<Stream> GetStreamAsync(string uri)
        {
            TaskFactory factory = new TaskFactory();
            WebRequest request = WebRequest.Create(uri);
            WebResponse response = await factory.FromAsync<WebResponse>(request.BeginGetResponse,
                                                                        request.EndGetResponse, null);
            return response.GetResponseStream(); 
        }
    }
}


요즘 많이 들리는 RAG에 대한 멋진 정리가 있어서 공유합니다. ㅎㅎ

 작년에는 ChatGPT가 크게 유행을 했는데 올해는 Gen AI, LLM, 랭체인등이 유행하고 있습니다. ㅎㅎ  RAG라는 단어도 상당히 많이 들리고 있습니다. 멋진 정리의 링크입니다.  https://brunch.co.kr/@ywkim36/146?...