Tuesday, November 19, 2019

Fixing Keyboard Hide When Reload UITableview iOS swift 5


Hello guys, If you ever worked with UITableview and UITextView or UITextfield. Like chat App or Comment app. You will face the keyboard will hide or in other word the keyboard close to down. And If we other famous apps like Instagram, it's not close but still exist even if we type and send messages.

And In this article I want to share with you guys, how to avoid it so you can easily make the keyboard always opened guys. I found many solution on the internet but some are bad because the keyboard have animation close and open again.

I used UITextview and customize it using GrowingTextView. Because I want to the Textbox change the height when user make a new line. So it will look like Whatsapp chat and It looks good. And I make the textbox above keyboard so it will make the user easily type and send messages.

The point is to make a new class custom and override canResignFirstResponder variable. So we can change it in our own class view controller. And that's good because that's the cause why the keyboard hide and show again. When you set canResignFirstResponder to false. The keyboard will not dismiss even you change page. So we need to set it back to false in viewWillDisappear method to make it close.

And this is the code you're waiting for guys.

Monday, November 11, 2019

Avoid Wrong Height UITableView When Reload and Add New Row


I have a problem where I can't find the solution on the internet like google, stackoverflow and blogs. So I need to trick this so that It work like I want. It's like the bug from iOS because what's supposed to be i'm doing it's the correct way. And the error seems weird because it's only sometimes happened.
I try to find it by way and it takes long time. And finally I got the solution but I think it's not final solution but I hope iOS will fix the issue soon.

So the error it's when you first time entering UITableview.  If you dynamic height like instagram did, you will sometimes get wrong height. But if it's not you are saved. I don't know if this problem only happened to me or not but after a few years expierence. I think this bug happened not only me.

My solution is not the best but I think it's really good to hide the pain because of this annoying bug haha. What I did is to refresh three times refresh when first reload UITableview. So if you have opened the UITableview before don't need to recall it again. Because it will make the memory bad.

Tuesday, November 5, 2019

Add Loading ActivityIndicator in AVPlayer Video iOS Swift 5



This week, I want to show loading after I have a video player that uses AVPlayer library. If you're curious like me. Stay tuned in this blog or if you're in hurry just scrolling on bottom. I must've given the source code. If you're an expert it must be easy to follow.

So if you don't use playback controller library AVPlayerViewController. I mean maybe you use AVPlayer Layer. It's basically it doesn't have playback controls. It's good to use loading Activity Indicator so the user will have a good expierence to operate our app.

So basically the AVplayer itself has a loading indicator beside play/pause button as you can see on above image. But it's not enough for me because it's too little, I need something on center like I do in UIImageview or loading something like loading API.

And the problem with AVPlayer, it doesn't have delegation to perform loading action so we need to use observer to do it. And don't forget to add the ActivityIndicator itself. Define it on public class but it doesn't matter if it is in method class.


Tuesday, October 29, 2019

How to get thumbnail from video URL in Swift 5


If you want to show video in your app and you want to show thumbnail. The easy way is to get image url from server API. But there is more easy way you just need to get url video and get image url. I have searched on the internet but what I found my app becomes lag. I use UITableview to show the video thumbnail url.

Maybe you wonder why I use image thumbnail. I can use video player from iOS and thumbnail video will be shown. But what if you use many thumbnail in UITableview, it will be heavy in the device. It's bad design too.

It will be good for you, if you can combine this extension image with SDWebImage. Because the image will be in cache and you don't need to reload image again. But you still need the internet to load the video url. Because it's online from the internet.

This is swift code and about objective-c code, it's better you search on the internet. I know it's really painful to change it to swift if you have developed big app. So you can convert swift to objective-c but it's not sure there will be a match library between swift and objective-c.

Tuesday, October 22, 2019

Create Rectangle Bubble Chat iOS Swift 5


Hello all, every week I try to give you a good tutorial to add your skill and knowledge too. And today you got to be suprised because It's not usually tutorial. I need to dig it deep down to present it. So if you want to create chat application, it's good for you. You can take it as reference.

So in chat application, you will face chat from bottom to up. As a screenshoot above, you can see it's not from top to bottom but otherwise. There is bubble chat on left and right. You can say when you send it will be on right and when someone send, it will be on left.

And about text height, it must be flexible height. Like app chat line or whatsapp, there is no cut in height. So it can small or so high. So we need to calculate the height. And about the width it's not full, we give space to the right or left.

I include the title header too so It will be more like chat app. The header will be on viewForFooterInSection why ? Because I reverse the UITableview, so the chat will be on bottom to top. As you can see on image above.

I create UIlabel date after message like chat app usually. So it will be complete for you to implement. And sorry if I don't give you full Source Code because it's easy to follow when you the code. So this is the code..