Author Archive

Add header effect as Path App.

วันนี้หาวิธีทำ Header ชอง Table ให้มี effect แบบแอพหล่อๆ อย่าง Path และเจอเว็บนึงอธิบายไว้ดีมาก และจริงๆ แล้วไม่ได้ยากเลยครับ

ตามลิงค์ไปอ่านได้ >> คลิกเลย

Superview & Touch + PanGesture

เราสามารถ access parent view ของ UIView และ subclass ของ UIView display object ได้ด้วย property  ”superview” เช่น myBtn.superview.frame.size.width สะดวกจุงเบย

การพยายามใช้ event touchesBegan/Moved/Ended ไปพร้อมๆ กับ event scrolling วิธีที่ดีที่สุด คือ ใช้ UIPanGestureRecognizer ช่วยในส่วนของการเคลื่อนที่แทน การใช้ nextResponder ใน touches events

 

การทำงานกับเสียงใน iOS

หลังจากหาข้อสรุปมาช่วงนึง ก็ได้เวลาหาข้อมูลจริงๆ จัง จนพอได้ข้อสรุปที่ใช้เป็นแนวทางได้ จึงอยากเอามาแชร์ให้ทุกคน เผื่อจะได้ประหยัดเวลาในการเลือกใช้ api ต่างๆ ที่มีมาให้ (เยอะเหลือเกิน) ใน iOS

Objective-C (iOS)  working with audio:

  • OpenAL :  when you want a convenient, high-level interface for positioning sounds in a stereo field or when you need low latency playback.
  • Audio File Stream Services  :  to parse audio packets from a file or a network stream.
  • AVAudioPlayer class  :  For simple playback of single or multiple sounds
  • AVAudioRecorder class  :  For recording to a file
  • Voice Processing I/O unit  :  for audio chat
  • iPod Library Access  :  To play audio resources synced from a user’s iTunes library
  • Core Audio’s System Sound Services  :  When your sole audio need is to play alerts and user-interface sound effects.
  • Audio Queue Services  :  For other audio applications, including playback of streamed audio, precise synchronisation, and access to packets of incoming audio.

ข้อมูลเพิ่มเติม อ่านต่อได้ ที่นี่

Get system time and check time pass in Objective-C

Tips: เราสามารถเช็ค ระยะเวลาการประมวลผลของคำสั่งในแต่ละบรรทัด หรือบล็อคของคำสั่ง ได้ง่ายๆ ด้วยวิธี:

NSDate *startDate = [NSDate date];
….

// processing something here …

NSTimeInterval elapsedTimeInterval = [startDate timeIntervalSinceNow];
NSLog(@”>>>>>>>>>>>>>>>> = %f”, elapsedTimeInterval);

ผลลัพธ์ที่ได้เป็นหน่วยวินาที (ติดลบ)

Falling fun fun

ยังไงๆ ผมก็ว่า การเขียนแฟลชนี่ มีความยืดหยุ่นสูงจริงๆ แต่อาจจะทำให้เรารู้สึกเสียนิสัยและอึดอัดใจในการเขียนโปรแรกมภาษาอื่นๆ ได้ เมื่อไม่มี dynamic variable หรือ object ที่มีความยืดหยุ่นสูงในการใช้งานอย่าง MovieClip :)

Simple Swing

Math: Swing + Gravity + Rotaion = falling leaf ครับ

ว่าแล้ว ลองมาดู pseudo code แบบคร่าวๆ นะครับ
- Generate random leaf
- add force เริ่มต้น gravity, rotation force, swing force
- ขนาดในการเริ่มต้นมีผลต่อ แรง Gravity (Vy), spin + swing
- แยกลูปในการสร้างใบไม้ และลูปในการ animate
- ถ้าใบไม้ล่วงถึงพื้น ให้ลบตัวเองจากกลุ่ม animate
- แสดงเงาบนพื้น
- ตั้งเวลาในการลบตัวเองออกจาก stage เพื่อลด memory

อืมมมม มันส์นิดๆ

Connect Camera is easy, turn it off is evil!!

To turn it on is so simple as document said but to turn it off after access need specific method. After google around I found this one solution:

video.attachCamera(null);
video.clear();
removeChild(_video);
camera = null;

ref: http://www.ninjabonsai.net/blog/?p=80

I test in an empty fla and it work like a charm. But when I test in my working project which do a lot more of connect and display video. I found that another important trick to do is below:

var cam:Camera = Camera.getCamera( id );
video.attachCamera(null);  // this need to set before the next line, always.
video.attachCamera(cam);

I know it weird but it work well for me.

หลุมพลาง Auto Scaling feature จาก corona

เคสนี้เรียกว่า “ขุดหลุมฝังตัวเอง” เกิดการแสดงขนาดภาพเพี้ยนในเกมส์ จากการพยายาม swap ภาพเองเมื่อ resolution ของ devices สูง

จากกำหนดการแสดงผลของ Application ไว้ที่ resolution ต่ำๆ เช่น 320×480 และทำการแสดงผลภาพบน retina display / ipad corona จะทำการปรับภาพเป็น dynamic scale โดยหากภาพที่ใช้การโหลดรูปแบบ newImageRect() จะได้รับการเปลี่ยนภาพให้โดยอัตโนมัติ เป็นชุด 2x แต่ภาพที่โหลดแบบ newImage() ต้องใส่ parameter เพื่อบังคับให้แสดงแบบไม่ dynamic scale เพิ่ม เมื่อทำการเปลี่ยนภาพเองผ่านโปรแกรม !!

ที่สำคัญ คือ simulator จะไม่แสดง error แต่เมื่อทดสอบใน devices จึงจะพบ…T T

การเคลื่อนไหวแบบสวิง

การสร้างการเคลื่อนไหวผ่านสคริป สำหรับการเคลื่อนไหวแบบแกว่งไปมา เป็นลูกตุ้มหรือคลื่น บางครั้งอาจจะดูเหมือนยาก แต่จริงๆ แล้วสามารถทำได้ง่ายๆ ด้วยฟังก์ชั่น math.cos() นั่นเอง

สมการ: math.cos(n)*force
- n คือ ค่าองศาที่เพิ่มขึ้นตามเวลา
- force คือ amplitude ที่เราต้องการ

ผลลัพธ์อย่างที่เห็นครับ :)
Simple Swing

Ten Principles for Good Design

I’m really like this presentation and the ideas of the “Good Design”, thinks that can apply to any kind of work even the web site.

1. Good design is innovative.
2. Good design makes a product useful.
3. Good design is aesthetic.
4. Good design makes a product understandable.
5. Good design is unobtrusive.
6. Good design is honest.
7. Good design is long-lasting.
8. Good design is thorough down to the last detail.
9. Good design is environmentally friendly.
10. Good design is as little design as possible.
Dieter Rams (1985).

Scale 9 Grid with Gradient work around!!

Today I’ve try to create a scale 9 shape with gradient fill in its shape and found that when create the scale 9 from IDE the gradient will not slice into scale 9 properly. So the result look like it is stretch. The work around that I found after googling for a while is use “Union” command to the out side border of the scale 9 by select menu “Modify/Objects/Union” and it work !! :)