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(); 
        }
    }
}


송길영 작가의 신간 - "경량문명의 탄생" 독서 후기입니다.

  문명이 바뀌고 있다는 것을 누구나 감지하고 있습니다. ㅎㅎ 중량문명이 아닌 경량문명의 시대가 도래하고 있습니다. 수업을 하면서, 또는 친구들과 대화하면서 문명이 바뀌고 있다는 말을 자주했는데 정말 설명하기 좋은 단어가 바로 "경량문명...